Skip to content

Commit

Permalink
Deleted stamped immutable objects do not cause error (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
waciumawanjohi authored Mar 10, 2023
1 parent 1dd27e3 commit 11c2faa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func immutableEquivalenceTest(realizedResource v1alpha1.ResourceStatus, prevReso
return false, fmt.Errorf("get unstructured: %w", err)
}

if prevObj == nil {
return false, nil
}

prevLabels := prevObj.GetLabels()

if lifecycleLabel, ok := prevLabels["carto.run/template-lifecycle"]; !ok || lifecycleLabel == "mutable" {
Expand Down
38 changes: 38 additions & 0 deletions pkg/controllers/workload_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,44 @@ var _ = Describe("WorkloadReconciler", func() {
})
})
})

Context("when the previously stamped object no longer exists", func() {
BeforeEach(func() {
referenceToNonExistentObject := v1alpha1.RealizedResource{
Name: "some-resource",
StampedRef: &v1alpha1.StampedRef{
ObjectReference: &corev1.ObjectReference{
APIVersion: "some-api-version",
Kind: "some-kind",
Name: "some-obj-name",
},
Resource: "some-kind",
},
TemplateRef: &corev1.ObjectReference{
Name: "some-template-name",
Kind: "some-template-kind",
},
}

wl.Status.Resources = []v1alpha1.ResourceStatus{
{
RealizedResource: referenceToNonExistentObject,
},
}
repo.GetWorkloadReturns(wl, nil)

repo.GetUnstructuredReturnsOnCall(0, nil, nil)
repo.DeleteReturns(fmt.Errorf("some error"))
})

It("does not return an error", func() {
_, err := reconciler.Reconcile(ctx, req)
Expect(err).NotTo(HaveOccurred())

Expect(repo.DeleteCallCount()).To(Equal(1))
Expect(out).To(Say(`"msg":"failed to cleanup orphaned objects","workload":"my-namespace/my-workload-name"`))
})
})
})

Context("when previous resource was stamped from a template that is no longer on cluster", func() {
Expand Down

0 comments on commit 11c2faa

Please sign in to comment.