@@ -374,8 +374,14 @@ func (sc *syncContext) Sync() {
374
374
// to perform the sync. we only wish to do this once per operation, performing additional dry-runs
375
375
// is harmless, but redundant. The indicator we use to detect if we have already performed
376
376
// 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 {
379
385
sc .setOperationPhase (common .OperationFailed , "one or more objects failed to apply (dry run)" )
380
386
return
381
387
}
@@ -448,13 +454,7 @@ func (sc *syncContext) Sync() {
448
454
tasks = tasks .Filter (func (t * syncTask ) bool { return t .pending () })
449
455
450
456
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 )
458
458
}
459
459
460
460
// If no sync tasks were generated (e.g., in case all application manifests have been removed),
@@ -513,6 +513,21 @@ func (sc *syncContext) Sync() {
513
513
}
514
514
}
515
515
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
+
516
531
func (sc * syncContext ) deleteHooks (hooksPendingDeletion syncTasks ) {
517
532
for _ , task := range hooksPendingDeletion {
518
533
err := sc .deleteResource (task )
0 commit comments