@@ -782,25 +782,24 @@ func removeStorageClaimAsOwner(obj client.Object) {
782
782
func (r * storageClientReconcile ) EnsureClusterScopedResource (obj client.Object , extRes * providerpb.ExternalResource , useReplace bool ) error {
783
783
obj .SetName (extRes .Name )
784
784
785
- if err := json .Unmarshal (extRes .Data , obj ); err != nil {
786
- return fmt .Errorf ("failed to unmarshal %s configuration response: %v" , obj .GetName (), err )
787
- }
788
- removeStorageClaimAsOwner (obj )
789
- if err := r .own (obj ); err != nil {
790
- return fmt .Errorf ("failed to own %s resource: %v" , obj .GetName (), err )
785
+ mutateFunc := func () error {
786
+ if err := json .Unmarshal (extRes .Data , obj ); err != nil {
787
+ return fmt .Errorf ("failed to unmarshal %s configuration response: %v" , obj .GetName (), err )
788
+ }
789
+ removeStorageClaimAsOwner (obj )
790
+ if err := r .own (obj ); err != nil {
791
+ return fmt .Errorf ("failed to own %s resource: %v" , obj .GetName (), err )
792
+ }
793
+ utils .AddLabels (obj , extRes .Labels )
794
+ utils .AddAnnotations (obj , extRes .Annotations )
795
+ return nil
791
796
}
792
- utils .AddLabels (obj , extRes .Labels )
793
- utils .AddAnnotations (obj , extRes .Annotations )
794
797
795
798
var err error
796
799
if useReplace {
797
- err = utils .CreateOrReplace (r .ctx , r .Client , obj , func () error {
798
- return nil
799
- })
800
+ err = utils .CreateOrReplace (r .ctx , r .Client , obj , mutateFunc )
800
801
} else {
801
- err = r .createOrUpdate (obj , func () error {
802
- return nil
803
- })
802
+ err = r .createOrUpdate (obj , mutateFunc )
804
803
}
805
804
806
805
if err != nil {
0 commit comments