Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ type ControllerSetupFunc func(c ControllerSetup) error
// - Deployed - a release for this CR is deployed (but not necessarily ready).
// - ReleaseFailed - an installation or upgrade failed.
// - Irreconcilable - an error occurred during reconciliation
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
log := r.log.WithValues(strings.ToLower(r.gvk.Kind), req.NamespacedName)
log.V(1).Info("Reconciliation triggered")

obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(*r.gvk)
err := r.client.Get(ctx, req.NamespacedName, obj)
err = r.client.Get(ctx, req.NamespacedName, obj)
if apierrors.IsNotFound(err) {
log.V(1).Info("Resource %s/%s not found, nothing to do", req.NamespacedName.Namespace, req.NamespacedName.Name)
return ctrl.Result{}, nil
Expand Down
46 changes: 44 additions & 2 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,15 @@ var _ = Describe("Reconciler", func() {
Patch: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, patch client.Patch, opts ...client.PatchOption) error {
return mgr.GetClient().Patch(ctx, fakeObj, patch, opts...)
},
SubResource: func(_ client.WithWatch, subresource string) client.SubResourceClient {
return mgr.GetClient().SubResource(subresource)
SubResourceUpdate: func(ctx context.Context, client client.Client, subResourceName string, obj client.Object, opts ...client.SubResourceUpdateOption) error {
// workaround https://github.com/kubernetes/kubernetes/issues/124347
err := mgr.GetClient().SubResource(subResourceName).Update(ctx, obj, opts...)
if err != nil {
if apierrors.IsConflict(err) {
return apierrors.NewNotFound(gvk.GroupVersion().WithResource("testapps").GroupResource(), obj.GetName())
}
}
return nil
},
}).WithStatusSubresource(obj).Build()
r.client = cl
Expand All @@ -752,6 +759,41 @@ var _ = Describe("Reconciler", func() {
})
})
})
When("errors that were not 'NotFound' occurred while applying CR status", func() {
It("should propagate apply errors to reconciler", func() {
By("configuring a client that will error during apply", func() {
// Make a client that returns the stale CR, but sends writes to the real client.
cl := fake.NewClientBuilder().WithObjects(obj).WithInterceptorFuncs(interceptor.Funcs{
Create: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, opts ...client.CreateOption) error {
return mgr.GetClient().Create(ctx, fakeObj, opts...)
},
Delete: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, opts ...client.DeleteOption) error {
return mgr.GetClient().Delete(ctx, fakeObj, opts...)
},
DeleteAllOf: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, opts ...client.DeleteAllOfOption) error {
return mgr.GetClient().DeleteAllOf(ctx, fakeObj, opts...)
},
Update: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, opts ...client.UpdateOption) error {
return mgr.GetClient().Update(ctx, fakeObj, opts...)
},
Patch: func(ctx context.Context, _ client.WithWatch, fakeObj client.Object, patch client.Patch, opts ...client.PatchOption) error {
return mgr.GetClient().Patch(ctx, fakeObj, patch, opts...)
},
SubResourceUpdate: func(ctx context.Context, client client.Client, subResourceName string, obj client.Object, opts ...client.SubResourceUpdateOption) error {
return apierrors.NewBadRequest("XXXInvalidXXX")
},
}).WithStatusSubresource(obj).Build()
r.client = cl
})

By("successfully ignoring not found errors and returning a nil error", func() {
res, err := r.Reconcile(ctx, req)
Expect(res).To(Equal(reconcile.Result{}))
Expect(err).To(HaveOccurred())
Expect(apierrors.IsBadRequest(err)).To(BeTrue())
})
})
})
When("CR is deleted, release is not present, but uninstall finalizer exists", func() {
It("removes the finalizer", func() {
By("adding the uninstall finalizer and deleting the CR", func() {
Expand Down