diff --git a/controllers/kustomization_controller.go b/controllers/kustomization_controller.go index c3df0a48..d90f89c1 100644 --- a/controllers/kustomization_controller.go +++ b/controllers/kustomization_controller.go @@ -647,6 +647,9 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour return false, nil, err } + applyOpts := ssa.DefaultApplyOptions() + applyOpts.Force = kustomization.Spec.Force + // contains only CRDs and Namespaces var stageOne []*unstructured.Unstructured @@ -668,7 +671,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour // validate, apply and wait for CRDs and Namespaces to register if len(stageOne) > 0 { - changeSet, err := manager.ApplyAll(ctx, stageOne, kustomization.Spec.Force) + changeSet, err := manager.ApplyAll(ctx, stageOne, applyOpts) if err != nil { return false, nil, err } @@ -683,7 +686,10 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour } } - if err := manager.Wait(stageOne, 2*time.Second, kustomization.GetTimeout()); err != nil { + if err := manager.Wait(stageOne, ssa.WaitOptions{ + Interval: 2 * time.Second, + Timeout: kustomization.GetTimeout(), + }); err != nil { return false, nil, err } } @@ -691,7 +697,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context, manager *ssa.Resour // sort by kind, validate and apply all the others objects sort.Sort(ssa.SortableUnstructureds(stageTwo)) if len(stageTwo) > 0 { - changeSet, err := manager.ApplyAll(ctx, stageTwo, kustomization.Spec.Force) + changeSet, err := manager.ApplyAll(ctx, stageTwo, applyOpts) if err != nil { return false, nil, fmt.Errorf("%w\n%s", err, changeSetLog.String()) } @@ -757,7 +763,10 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context, manager *ssa. } // check the health with a default timeout of 30sec shorter than the reconciliation interval - if err := manager.WaitForSet(toCheck, time.Second, kustomization.GetTimeout()); err != nil { + if err := manager.WaitForSet(toCheck, ssa.WaitOptions{ + Interval: 5 * time.Second, + Timeout: kustomization.GetTimeout(), + }); err != nil { return fmt.Errorf("Health check failed after %s, %w", time.Now().Sub(checkStart).String(), err) } @@ -776,12 +785,16 @@ func (r *KustomizationReconciler) prune(ctx context.Context, manager *ssa.Resour } log := logr.FromContext(ctx) - changeSet, err := manager.DeleteAll(ctx, objects, - manager.GetOwnerLabels(kustomization.Name, kustomization.Namespace), - map[string]string{ + + opts := ssa.DeleteOptions{ + PropagationPolicy: metav1.DeletePropagationBackground, + Inclusions: manager.GetOwnerLabels(kustomization.Name, kustomization.Namespace), + Exclusions: map[string]string{ fmt.Sprintf("%s/prune", kustomizev1.GroupVersion.Group): kustomizev1.DisabledValue, }, - ) + } + + changeSet, err := manager.DeleteAll(ctx, objects, opts) if err != nil { return false, err } @@ -817,12 +830,15 @@ func (r *KustomizationReconciler) finalize(ctx context.Context, kustomization ku Group: kustomizev1.GroupVersion.Group, }) - changeSet, err := resourceManager.DeleteAll(ctx, objects, - resourceManager.GetOwnerLabels(kustomization.Name, kustomization.Namespace), - map[string]string{ + opts := ssa.DeleteOptions{ + PropagationPolicy: metav1.DeletePropagationBackground, + Inclusions: resourceManager.GetOwnerLabels(kustomization.Name, kustomization.Namespace), + Exclusions: map[string]string{ fmt.Sprintf("%s/prune", kustomizev1.GroupVersion.Group): kustomizev1.DisabledValue, }, - ) + } + + changeSet, err := resourceManager.DeleteAll(ctx, objects, opts) if err != nil { r.event(ctx, kustomization, kustomization.Status.LastAppliedRevision, events.EventSeverityError, "pruning for deleted resource failed", nil) // Return the error so we retry the failed garbage collection diff --git a/go.mod b/go.mod index 71ec7b90..d2eb0340 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/fluxcd/pkg/apis/kustomize v0.2.0 github.com/fluxcd/pkg/apis/meta v0.10.1 github.com/fluxcd/pkg/runtime v0.12.2 - github.com/fluxcd/pkg/ssa v0.2.0 + github.com/fluxcd/pkg/ssa v0.3.1 github.com/fluxcd/pkg/testserver v0.1.0 github.com/fluxcd/pkg/untar v0.1.0 github.com/fluxcd/source-controller/api v0.16.0 diff --git a/go.sum b/go.sum index c90ad437..16fc25e9 100644 --- a/go.sum +++ b/go.sum @@ -225,8 +225,8 @@ github.com/fluxcd/pkg/apis/meta v0.10.1/go.mod h1:yUblM2vg+X8TE3A2VvJfdhkGmg+uqB github.com/fluxcd/pkg/runtime v0.12.0/go.mod h1:EyaTR2TOYcjL5U//C4yH3bt2tvTgIOSXpVRbWxUn/C4= github.com/fluxcd/pkg/runtime v0.12.2 h1:4iOpx2j/w15kNemDOnZrF6ugJ/rhSmRu7aI+xn23+BI= github.com/fluxcd/pkg/runtime v0.12.2/go.mod h1:tuWdqpWPhgjQvYrSnojdZ4plyU8DRU1NDzsfOhnzl2g= -github.com/fluxcd/pkg/ssa v0.2.0 h1:5GTBnnWJhiSIKI1TZQ20ioWjTPNkEof2V2uN0ZHUxDs= -github.com/fluxcd/pkg/ssa v0.2.0/go.mod h1:rFhWBX9/TfNwSFR+5NHOGnpl9OsWdaQrG5CggN+74EQ= +github.com/fluxcd/pkg/ssa v0.3.1 h1:lKjTRQmSWFEXpKJadK9Fu0GSLL8lv0k5muIcc+7hZIs= +github.com/fluxcd/pkg/ssa v0.3.1/go.mod h1:rFhWBX9/TfNwSFR+5NHOGnpl9OsWdaQrG5CggN+74EQ= github.com/fluxcd/pkg/testserver v0.1.0 h1:nOYgM1HYFZNNSUFykuWDmrsxj4jQxUCvmLHWOQeqmyA= github.com/fluxcd/pkg/testserver v0.1.0/go.mod h1:fvt8BHhXw6c1+CLw1QFZxcQprlcXzsrL4rzXaiGM+Iw= github.com/fluxcd/pkg/untar v0.1.0 h1:k97V/xV5hFrAkIkVPuv5AVhyxh1ZzzAKba/lbDfGo6o=