@@ -116,6 +116,13 @@ func WithPrune(prune bool) SyncOpt {
116
116
}
117
117
}
118
118
119
+ // WithPruneConfirmed specifies if prune is confirmed for resources that require confirmation
120
+ func WithPruneConfirmed (confirmed bool ) SyncOpt {
121
+ return func (ctx * syncContext ) {
122
+ ctx .pruneConfirmed = confirmed
123
+ }
124
+ }
125
+
119
126
// WithOperationSettings allows to set sync operation settings
120
127
func WithOperationSettings (dryRun bool , prune bool , force bool , skipHooks bool ) SyncOpt {
121
128
return func (ctx * syncContext ) {
@@ -339,6 +346,7 @@ type syncContext struct {
339
346
serverSideApplyManager string
340
347
pruneLast bool
341
348
prunePropagationPolicy * metav1.DeletionPropagation
349
+ pruneConfirmed bool
342
350
343
351
syncRes map [string ]common.ResourceSyncResult
344
352
startedAt time.Time
@@ -1149,6 +1157,24 @@ func (sc *syncContext) runTasks(tasks syncTasks, dryRun bool) runState {
1149
1157
}
1150
1158
// prune first
1151
1159
{
1160
+ if ! sc .pruneConfirmed {
1161
+ var resources []string
1162
+ for _ , task := range pruneTasks {
1163
+ if resourceutil .HasAnnotationOption (task .liveObj , common .AnnotationSyncOptions , common .SyncOptionPruneRequireConfirm ) {
1164
+ resources = append (resources , fmt .Sprintf ("%s/%s/%s" , task .obj ().GetAPIVersion (), task .obj ().GetKind (), task .name ()))
1165
+ }
1166
+ }
1167
+ if len (resources ) > 0 {
1168
+ sc .log .WithValues ("resources" , resources ).Info ("Prune requires confirmation" )
1169
+ andMessage := ""
1170
+ if len (resources ) > 1 {
1171
+ andMessage = fmt .Sprintf (" and %d more resources" , len (resources )- 1 )
1172
+ }
1173
+ sc .message = fmt .Sprintf ("Waiting for pruning confirmation of %s%s" , resources [0 ], andMessage )
1174
+ return pending
1175
+ }
1176
+ }
1177
+
1152
1178
ss := newStateSync (state )
1153
1179
for _ , task := range pruneTasks {
1154
1180
t := task
0 commit comments