@@ -59,6 +59,13 @@ type SyncContext interface {
59
59
// SyncOpt is a callback that update sync operation settings
60
60
type SyncOpt func (ctx * syncContext )
61
61
62
+ // WithPrunePropagationPolicy sets specified permission validator
63
+ func WithPrunePropagationPolicy (policy * metav1.DeletionPropagation ) SyncOpt {
64
+ return func (ctx * syncContext ) {
65
+ ctx .prunePropagationPolicy = policy
66
+ }
67
+ }
68
+
62
69
// WithPermissionValidator sets specified permission validator
63
70
func WithPermissionValidator (validator common.PermissionValidator ) SyncOpt {
64
71
return func (ctx * syncContext ) {
@@ -292,13 +299,14 @@ type syncContext struct {
292
299
kubectl kube.Kubectl
293
300
namespace string
294
301
295
- dryRun bool
296
- force bool
297
- validate bool
298
- skipHooks bool
299
- resourcesFilter func (key kube.ResourceKey , target * unstructured.Unstructured , live * unstructured.Unstructured ) bool
300
- prune bool
301
- pruneLast bool
302
+ dryRun bool
303
+ force bool
304
+ validate bool
305
+ skipHooks bool
306
+ resourcesFilter func (key kube.ResourceKey , target * unstructured.Unstructured , live * unstructured.Unstructured ) bool
307
+ prune bool
308
+ pruneLast bool
309
+ prunePropagationPolicy * metav1.DeletionPropagation
302
310
303
311
syncRes map [string ]common.ResourceSyncResult
304
312
startedAt time.Time
@@ -820,9 +828,7 @@ func (sc *syncContext) pruneObject(liveObj *unstructured.Unstructured, prune, dr
820
828
// Skip deletion if object is already marked for deletion, so we don't cause a resource update hotloop
821
829
deletionTimestamp := liveObj .GetDeletionTimestamp ()
822
830
if deletionTimestamp == nil || deletionTimestamp .IsZero () {
823
- propagationPolicy := metav1 .DeletePropagationForeground
824
- deleteOption := metav1.DeleteOptions {PropagationPolicy : & propagationPolicy }
825
- err := sc .kubectl .DeleteResource (context .TODO (), sc .config , liveObj .GroupVersionKind (), liveObj .GetName (), liveObj .GetNamespace (), deleteOption )
831
+ err := sc .kubectl .DeleteResource (context .TODO (), sc .config , liveObj .GroupVersionKind (), liveObj .GetName (), liveObj .GetNamespace (), sc .getDeleteOptions ())
826
832
if err != nil {
827
833
return common .ResultCodeSyncFailed , err .Error ()
828
834
}
@@ -832,6 +838,15 @@ func (sc *syncContext) pruneObject(liveObj *unstructured.Unstructured, prune, dr
832
838
}
833
839
}
834
840
841
+ func (sc * syncContext ) getDeleteOptions () metav1.DeleteOptions {
842
+ propagationPolicy := metav1 .DeletePropagationForeground
843
+ if sc .prunePropagationPolicy != nil {
844
+ propagationPolicy = * sc .prunePropagationPolicy
845
+ }
846
+ deleteOption := metav1.DeleteOptions {PropagationPolicy : & propagationPolicy }
847
+ return deleteOption
848
+ }
849
+
835
850
func (sc * syncContext ) targetObjs () []* unstructured.Unstructured {
836
851
objs := sc .hooks
837
852
for _ , r := range sc .resources {
@@ -907,8 +922,7 @@ func (sc *syncContext) deleteResource(task *syncTask) error {
907
922
if err != nil {
908
923
return err
909
924
}
910
- propagationPolicy := metav1 .DeletePropagationForeground
911
- return resIf .Delete (context .TODO (), task .name (), metav1.DeleteOptions {PropagationPolicy : & propagationPolicy })
925
+ return resIf .Delete (context .TODO (), task .name (), sc .getDeleteOptions ())
912
926
}
913
927
914
928
func (sc * syncContext ) getResourceIf (task * syncTask ) (dynamic.ResourceInterface , error ) {
0 commit comments