@@ -34,6 +34,7 @@ import (
3434 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3535 "sigs.k8s.io/controller-runtime/pkg/log"
3636
37+ "github.com/sap/component-operator-runtime/internal/util"
3738 "github.com/sap/component-operator-runtime/pkg/cluster"
3839 "github.com/sap/component-operator-runtime/pkg/status"
3940 "github.com/sap/component-operator-runtime/pkg/types"
@@ -1318,7 +1319,7 @@ func (r *Reconciler) deleteObject(ctx context.Context, key types.ObjectKey, exis
13181319 }
13191320 if ok := controllerutil .RemoveFinalizer (crd , r .finalizer ); ok {
13201321 // note: 409 error is very likely here (because of concurrent updates happening through the api server); this is why we retry once
1321- if err := r . client . Update (ctx , crd , client . FieldOwner ( r .fieldOwner ) ); err != nil {
1322+ if err := util . UpdateFinalizers (ctx , r . client , crd , r .fieldOwner ); err != nil {
13221323 if i == 1 && apierrors .IsConflict (err ) {
13231324 log .V (1 ).Info ("error while updating CustomResourcedefinition (409 conflict); doing one retry" , "error" , err .Error ())
13241325 continue
@@ -1343,7 +1344,7 @@ func (r *Reconciler) deleteObject(ctx context.Context, key types.ObjectKey, exis
13431344 }
13441345 if ok := controllerutil .RemoveFinalizer (apiService , r .finalizer ); ok {
13451346 // note: 409 error is very likely here (because of concurrent updates happening through the api server); this is why we retry once
1346- if err := r . client . Update (ctx , apiService , client . FieldOwner ( r .fieldOwner ) ); err != nil {
1347+ if err := util . UpdateFinalizers (ctx , r . client , apiService , r .fieldOwner ); err != nil {
13471348 if i == 1 && apierrors .IsConflict (err ) {
13481349 log .V (1 ).Info ("error while updating APIService (409 conflict); doing one retry" , "error" , err .Error ())
13491350 continue
@@ -1365,13 +1366,15 @@ func (r *Reconciler) orphanObject(ctx context.Context, existingObject *unstructu
13651366 }
13661367
13671368 if existingObject .GetLabels ()[r .labelKeyOwnerId ] != hashedOwnerId {
1368- return fmt .Errorf ("owner conflict; object %s has no or different owner" , types .ObjectKeyToString (existingObject ))
1369+ // the object has a different owner; so we do not raise an owner id conflict error here
1370+ return nil
13691371 }
13701372
1373+ // do cleanup on orphaned object; note: this happens only if we own it; otherwise we already returned above
13711374 if isCrd (existingObject ) || isApiService (existingObject ) {
13721375 object := existingObject .DeepCopy ()
13731376 if controllerutil .RemoveFinalizer (object , r .finalizer ) {
1374- if err := r . client . Update (ctx , object , client . FieldOwner ( r .fieldOwner ) ); err != nil {
1377+ if err := util . UpdateFinalizers (ctx , r . client , object , r .fieldOwner ); err != nil {
13751378 return err
13761379 }
13771380 }
@@ -1528,9 +1531,11 @@ func (r *Reconciler) isTypeUsed(ctx context.Context, gk schema.GroupKind, hashed
15281531
15291532func (r * Reconciler ) isCrdUsed (ctx context.Context , crd * apiextensionsv1.CustomResourceDefinition , hashedOwnerId string , onlyForeign bool ) (bool , error ) {
15301533 gvk := schema.GroupVersionKind {
1531- Group : crd .Spec .Group ,
1532- Version : crd .Spec .Versions [0 ].Name ,
1533- Kind : crd .Spec .Names .Kind ,
1534+ Group : crd .Spec .Group ,
1535+ Version : slices .Select (crd .Spec .Versions , func (v apiextensionsv1.CustomResourceDefinitionVersion ) bool {
1536+ return v .Served
1537+ })[0 ].Name ,
1538+ Kind : crd .Spec .Names .Kind ,
15341539 }
15351540 list := & unstructured.UnstructuredList {}
15361541 list .SetGroupVersionKind (gvk )
0 commit comments