Skip to content

Commit

Permalink
Set delete propagation policy to background
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Nov 8, 2021
1 parent 6a3e01a commit f2715a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
40 changes: 28 additions & 12 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand All @@ -683,15 +686,18 @@ 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
}
}

// 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())
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit f2715a7

Please sign in to comment.