Skip to content

Commit 2a9c144

Browse files
authored
fix: applyoutofsync with dry-run (argoproj#253)
Signed-off-by: kshamajain99 <[email protected]>
1 parent 1ce2acc commit 2a9c144

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pkg/sync/sync_context.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,14 @@ func (sc *syncContext) Sync() {
374374
// to perform the sync. we only wish to do this once per operation, performing additional dry-runs
375375
// is harmless, but redundant. The indicator we use to detect if we have already performed
376376
// the dry-run for this operation, is if the resource or hook list is empty.
377-
sc.log.WithValues("tasks", tasks).Info("Tasks (dry-run)")
378-
if sc.runTasks(tasks, true) == failed {
377+
378+
dryRunTasks := tasks
379+
if sc.applyOutOfSyncOnly {
380+
dryRunTasks = sc.filterOutOfSyncTasks(tasks)
381+
}
382+
383+
sc.log.WithValues("tasks", dryRunTasks).Info("Tasks (dry-run)")
384+
if sc.runTasks(dryRunTasks, true) == failed {
379385
sc.setOperationPhase(common.OperationFailed, "one or more objects failed to apply (dry run)")
380386
return
381387
}
@@ -448,13 +454,7 @@ func (sc *syncContext) Sync() {
448454
tasks = tasks.Filter(func(t *syncTask) bool { return t.pending() })
449455

450456
if sc.applyOutOfSyncOnly {
451-
tasks = tasks.Filter(func(t *syncTask) bool {
452-
if modified, ok := sc.modificationResult[t.resourceKey()]; !modified && ok && t.targetObj != nil && t.liveObj != nil {
453-
sc.log.WithValues("resource key", t.resourceKey()).V(1).Info("Skipping as resource was not modified")
454-
return false
455-
}
456-
return true
457-
})
457+
tasks = sc.filterOutOfSyncTasks(tasks)
458458
}
459459

460460
// If no sync tasks were generated (e.g., in case all application manifests have been removed),
@@ -513,6 +513,21 @@ func (sc *syncContext) Sync() {
513513
}
514514
}
515515

516+
// filter out out-of-sync tasks
517+
func (sc *syncContext) filterOutOfSyncTasks(tasks syncTasks) syncTasks {
518+
return tasks.Filter(func(t *syncTask) bool {
519+
if t.isHook() {
520+
return true
521+
}
522+
523+
if modified, ok := sc.modificationResult[t.resourceKey()]; !modified && ok && t.targetObj != nil && t.liveObj != nil {
524+
sc.log.WithValues("resource key", t.resourceKey()).V(1).Info("Skipping as resource was not modified")
525+
return false
526+
}
527+
return true
528+
})
529+
}
530+
516531
func (sc *syncContext) deleteHooks(hooksPendingDeletion syncTasks) {
517532
for _, task := range hooksPendingDeletion {
518533
err := sc.deleteResource(task)

0 commit comments

Comments
 (0)