Skip to content

Commit 6f6d921

Browse files
authored
refactor: consistently use the same SetOwnerReference function (#713)
**What problem does this PR solve?**: Follow up to https://github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pull/711/files 😞 Realized that everywhere else we use this function instead. Unit tests are unchanged, and verified manually too that it all still works: ``` kind: Secret metadata: creationTimestamp: "2024-06-11T16:19:52Z" labels: cluster.x-k8s.io/provider: nutanix name: dkoshkin-nkp-secrets-ownership-7-pc-creds-for-csi namespace: default ownerReferences: - apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster name: dkoshkin-nkp-secrets-ownership-7 uid: fd102035-5f0b-4185-92d3-b08c251b775c ``` **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 7ee8f09 commit 6f6d921

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

pkg/handlers/generic/lifecycle/utils/secrets.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1313
"sigs.k8s.io/cluster-api/controllers/remote"
14-
"sigs.k8s.io/cluster-api/util"
1514
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
15+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1616

1717
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client"
1818
)
@@ -75,15 +75,10 @@ func EnsureOwnerRefForSecret(
7575
return err
7676
}
7777

78-
secret.OwnerReferences = util.EnsureOwnerRef(
79-
secret.OwnerReferences,
80-
metav1.OwnerReference{
81-
APIVersion: clusterv1.GroupVersion.String(),
82-
Kind: cluster.Kind,
83-
UID: cluster.UID,
84-
Name: cluster.Name,
85-
},
86-
)
78+
err = controllerutil.SetOwnerReference(cluster, secret, cl.Scheme())
79+
if err != nil {
80+
return fmt.Errorf("failed to set owner reference on Secret: %w", err)
81+
}
8782

8883
err = cl.Update(ctx, secret)
8984
if err != nil {

0 commit comments

Comments
 (0)