@@ -738,8 +738,15 @@ var _ = Describe("Reconciler", func() {
738
738
Patch : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
739
739
return mgr .GetClient ().Patch (ctx , fakeObj , patch , opts ... )
740
740
},
741
- SubResource : func (_ client.WithWatch , subresource string ) client.SubResourceClient {
742
- return mgr .GetClient ().SubResource (subresource )
741
+ SubResourceUpdate : func (ctx context.Context , _ client.Client , subResourceName string , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
742
+ err := mgr .GetClient ().SubResource (subResourceName ).Update (ctx , obj , opts ... )
743
+ if err != nil {
744
+ if apierrors .IsConflict (err ) {
745
+ // workaround https://github.com/kubernetes/kubernetes/issues/124347
746
+ return apierrors .NewNotFound (gvk .GroupVersion ().WithResource ("testapps" ).GroupResource (), obj .GetName ())
747
+ }
748
+ }
749
+ return nil
743
750
},
744
751
}).WithStatusSubresource (obj ).Build ()
745
752
r .client = cl
@@ -752,6 +759,44 @@ var _ = Describe("Reconciler", func() {
752
759
})
753
760
})
754
761
})
762
+ When ("errors that were not 'NotFound' occurred while applying CR status" , func () {
763
+ It ("should propagate apply errors to reconciler" , func () {
764
+ By ("configuring a client that will error during apply" , func () {
765
+ cl := fake .NewClientBuilder ().WithObjects (obj ).WithInterceptorFuncs (interceptor.Funcs {
766
+ Create : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , opts ... client.CreateOption ) error {
767
+ return mgr .GetClient ().Create (ctx , fakeObj , opts ... )
768
+ },
769
+ Delete : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , opts ... client.DeleteOption ) error {
770
+ return mgr .GetClient ().Delete (ctx , fakeObj , opts ... )
771
+ },
772
+ DeleteAllOf : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , opts ... client.DeleteAllOfOption ) error {
773
+ return mgr .GetClient ().DeleteAllOf (ctx , fakeObj , opts ... )
774
+ },
775
+ Update : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , opts ... client.UpdateOption ) error {
776
+ return mgr .GetClient ().Update (ctx , fakeObj , opts ... )
777
+ },
778
+ Patch : func (ctx context.Context , _ client.WithWatch , fakeObj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
779
+ return mgr .GetClient ().Patch (ctx , fakeObj , patch , opts ... )
780
+ },
781
+ SubResourceUpdate : func (_ context.Context , _ client.Client , _ string , _ client.Object , _ ... client.SubResourceUpdateOption ) error {
782
+ return apierrors .NewBadRequest ("XXXInvalidXXX" )
783
+ },
784
+ }).WithStatusSubresource (obj ).Build ()
785
+ r .client = cl
786
+ })
787
+
788
+ By ("propagating the error from status update" , func () {
789
+ res , err := r .Reconcile (ctx , req )
790
+ Expect (res ).To (Equal (reconcile.Result {}))
791
+ Expect (err ).To (HaveOccurred ())
792
+ Expect (apierrors .IsBadRequest (err )).To (BeTrue ())
793
+
794
+ var statusErr apierrors.APIStatus
795
+ Expect (errors .As (err , & statusErr )).To (BeTrue ())
796
+ Expect (statusErr .Status ().Message ).To (Equal ("XXXInvalidXXX" ))
797
+ })
798
+ })
799
+ })
755
800
When ("CR is deleted, release is not present, but uninstall finalizer exists" , func () {
756
801
It ("removes the finalizer" , func () {
757
802
By ("adding the uninstall finalizer and deleting the CR" , func () {
0 commit comments