Skip to content

Commit 5974e09

Browse files
committed
update IsAutomatedSyncEnabled func to return bool
Signed-off-by: Anand Kumar Singh <[email protected]>
1 parent 9e83f40 commit 5974e09

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

applicationset/controllers/applicationset_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ func (r *ApplicationSetReconciler) syncValidApplications(logCtx *log.Entry, appl
13981398
pruneEnabled := false
13991399

14001400
// ensure that Applications generated with RollingSync do not have an automated sync policy, since the AppSet controller will handle triggering the sync operation instead
1401-
if validApps[i].Spec.SyncPolicy != nil && *validApps[i].Spec.SyncPolicy.IsAutomatedSyncEnabled() {
1401+
if validApps[i].Spec.SyncPolicy != nil && validApps[i].Spec.SyncPolicy.IsAutomatedSyncEnabled() {
14021402
pruneEnabled = validApps[i].Spec.SyncPolicy.Automated.Prune
14031403
validApps[i].Spec.SyncPolicy.Automated = nil
14041404
}

cmd/argocd/commands/app.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ func printAppSummaryTable(app *argoappv1.Application, appURL string, windows *ar
664664
}
665665

666666
var syncPolicy string
667-
if app.Spec.SyncPolicy != nil && *app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
667+
if app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
668668
syncPolicy = "Automated"
669669
if app.Spec.SyncPolicy.Automated.Prune {
670670
syncPolicy += " (Prune)"
@@ -1726,7 +1726,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
17261726
}
17271727

17281728
func formatSyncPolicy(app argoappv1.Application) string {
1729-
if app.Spec.SyncPolicy == nil || !*app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
1729+
if app.Spec.SyncPolicy == nil || !app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
17301730
return "Manual"
17311731
}
17321732
policy := "Auto"
@@ -2158,7 +2158,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
21582158
}
21592159

21602160
if local != "" {
2161-
if app.Spec.SyncPolicy != nil && *app.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !dryRun {
2161+
if app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !dryRun {
21622162
log.Fatal("Cannot use local sync when Automatic Sync Policy is enabled except with --dry-run")
21632163
}
21642164

cmd/argocd/commands/applicationset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func printAppSetSummaryTable(appSet *arogappsetv1.ApplicationSet) {
460460
syncPolicyStr string
461461
syncPolicy = appSet.Spec.Template.Spec.SyncPolicy
462462
)
463-
if syncPolicy != nil && *syncPolicy.IsAutomatedSyncEnabled() {
463+
if syncPolicy != nil && syncPolicy.IsAutomatedSyncEnabled() {
464464
syncPolicyStr = "Automated"
465465
if syncPolicy.Automated.Prune {
466466
syncPolicyStr += " (Prune)"

cmd/util/app.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,19 @@ func SetAppSpecOptions(flags *pflag.FlagSet, spec *argoappv1.ApplicationSpec, ap
289289
}
290290
})
291291
if flags.Changed("auto-prune") {
292-
if spec.SyncPolicy == nil || !*spec.SyncPolicy.IsAutomatedSyncEnabled() {
292+
if spec.SyncPolicy == nil || !spec.SyncPolicy.IsAutomatedSyncEnabled() {
293293
log.Fatal("Cannot set --auto-prune: application not configured with automatic sync")
294294
}
295295
spec.SyncPolicy.Automated.Prune = appOpts.autoPrune
296296
}
297297
if flags.Changed("self-heal") {
298-
if spec.SyncPolicy == nil || !*spec.SyncPolicy.IsAutomatedSyncEnabled() {
298+
if spec.SyncPolicy == nil || !spec.SyncPolicy.IsAutomatedSyncEnabled() {
299299
log.Fatal("Cannot set --self-heal: application not configured with automatic sync")
300300
}
301301
spec.SyncPolicy.Automated.SelfHeal = appOpts.selfHeal
302302
}
303303
if flags.Changed("allow-empty") {
304-
if spec.SyncPolicy == nil || !*spec.SyncPolicy.IsAutomatedSyncEnabled() {
304+
if spec.SyncPolicy == nil || !spec.SyncPolicy.IsAutomatedSyncEnabled() {
305305
log.Fatal("Cannot set --allow-empty: application not configured with automatic sync")
306306
}
307307
spec.SyncPolicy.Automated.AllowEmpty = appOpts.allowEmpty

controller/appcontroller.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ func (ctrl *ApplicationController) autoSync(app *appv1.Application, syncStatus *
20602060
logCtx = logCtx.WithField("time_ms", time.Since(ts.StartTime).Milliseconds())
20612061
logCtx.Debug("Finished auto sync")
20622062
}()
2063-
if app.Spec.SyncPolicy == nil || !*app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
2063+
if app.Spec.SyncPolicy == nil || !app.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
20642064
return nil, 0
20652065
}
20662066

@@ -2486,14 +2486,14 @@ func isOperationInProgress(app *appv1.Application) bool {
24862486
func automatedSyncEnabled(oldApp *appv1.Application, newApp *appv1.Application) bool {
24872487
oldEnabled := false
24882488
oldSelfHealEnabled := false
2489-
if oldApp.Spec.SyncPolicy != nil && *oldApp.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
2489+
if oldApp.Spec.SyncPolicy != nil && oldApp.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
24902490
oldEnabled = true
24912491
oldSelfHealEnabled = oldApp.Spec.SyncPolicy.Automated.SelfHeal
24922492
}
24932493

24942494
newEnabled := false
24952495
newSelfHealEnabled := false
2496-
if newApp.Spec.SyncPolicy != nil && *newApp.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
2496+
if newApp.Spec.SyncPolicy != nil && newApp.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
24972497
newEnabled = true
24982498
newSelfHealEnabled = newApp.Spec.SyncPolicy.Automated.SelfHeal
24992499
}

controller/metrics/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (c *appCollector) collectApps(ch chan<- prometheus.Metric, app *argoappv1.A
412412
healthStatus = health.HealthStatusUnknown
413413
}
414414

415-
autoSyncEnabled := app.Spec.SyncPolicy != nil && *app.Spec.SyncPolicy.IsAutomatedSyncEnabled()
415+
autoSyncEnabled := app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.IsAutomatedSyncEnabled()
416416

417417
addGauge(descAppInfo, 1, strconv.FormatBool(autoSyncEnabled), git.NormalizeGitURL(app.Spec.GetSource().RepoURL), app.Spec.Destination.Server, app.Spec.Destination.Namespace, string(syncStatus), string(healthStatus), operation)
418418

pkg/apis/application/v1alpha1/types.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/argoproj/gitops-engine/pkg/health"
2323
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
2424
"github.com/argoproj/gitops-engine/pkg/utils/kube"
25-
"github.com/robfig/cron/v3"
2625
log "github.com/sirupsen/logrus"
2726
"google.golang.org/grpc/codes"
2827
"google.golang.org/grpc/status"
@@ -1433,13 +1432,13 @@ type SyncPolicy struct {
14331432
}
14341433

14351434
// IsAutomatedSyncEnabled checks if the automated sync is enabled or disabled
1436-
func (p *SyncPolicy) IsAutomatedSyncEnabled() *bool {
1435+
func (p *SyncPolicy) IsAutomatedSyncEnabled() bool {
14371436
var isEnabled bool
14381437

14391438
if p.Automated != nil && (p.Automated.Enable == nil || *p.Automated.Enable) {
14401439
isEnabled = true
14411440
}
1442-
return &isEnabled
1441+
return isEnabled
14431442
}
14441443

14451444
// IsZero returns true if the sync policy is empty

server/application/application.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ func (s *Server) Sync(ctx context.Context, syncReq *application.ApplicationSyncR
19481948
if err := s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceApplications, rbac.ActionOverride, a.RBACName(s.ns)); err != nil {
19491949
return nil, err
19501950
}
1951-
if a.Spec.SyncPolicy != nil && *a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
1951+
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
19521952
return nil, status.Error(codes.FailedPrecondition, "cannot use local sync when Automatic Sync Policy is enabled unless for dry run")
19531953
}
19541954
}
@@ -2048,7 +2048,7 @@ func (s *Server) resolveSourceRevisions(ctx context.Context, a *v1alpha1.Applica
20482048
sources[pos-1].TargetRevision = syncReq.Revisions[i]
20492049
}
20502050
for index, source := range sources {
2051-
if a.Spec.SyncPolicy != nil && *a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
2051+
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
20522052
if text.FirstNonEmpty(a.Spec.GetSources()[index].TargetRevision, "HEAD") != text.FirstNonEmpty(source.TargetRevision, "HEAD") {
20532053
return "", "", nil, nil, status.Errorf(codes.FailedPrecondition, "Cannot sync source %s to %s: auto-sync currently set to %s", source.RepoURL, source.TargetRevision, a.Spec.Sources[index].TargetRevision)
20542054
}
@@ -2063,7 +2063,7 @@ func (s *Server) resolveSourceRevisions(ctx context.Context, a *v1alpha1.Applica
20632063
return "", "", sourceRevisions, displayRevisions, nil
20642064
}
20652065
source := a.Spec.GetSource()
2066-
if a.Spec.SyncPolicy != nil && *a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
2066+
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.IsAutomatedSyncEnabled() && !syncReq.GetDryRun() {
20672067
if syncReq.GetRevision() != "" && syncReq.GetRevision() != text.FirstNonEmpty(source.TargetRevision, "HEAD") {
20682068
return "", "", nil, nil, status.Errorf(codes.FailedPrecondition, "Cannot sync to %s: auto-sync currently set to %s", syncReq.GetRevision(), source.TargetRevision)
20692069
}
@@ -2086,7 +2086,7 @@ func (s *Server) Rollback(ctx context.Context, rollbackReq *application.Applicat
20862086
if a.DeletionTimestamp != nil {
20872087
return nil, status.Errorf(codes.FailedPrecondition, "application is deleting")
20882088
}
2089-
if a.Spec.SyncPolicy != nil && *a.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
2089+
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.IsAutomatedSyncEnabled() {
20902090
return nil, status.Errorf(codes.FailedPrecondition, "rollback cannot be initiated when auto-sync is enabled")
20912091
}
20922092

0 commit comments

Comments
 (0)