Skip to content

Commit

Permalink
refactor: consistently use the same SetOwnerReference function (#713)
Browse files Browse the repository at this point in the history
**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.
-->
  • Loading branch information
dkoshkin authored Jun 11, 2024
1 parent 7ee8f09 commit 6f6d921
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pkg/handlers/generic/lifecycle/utils/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/remote"
"sigs.k8s.io/cluster-api/util"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client"
)
Expand Down Expand Up @@ -75,15 +75,10 @@ func EnsureOwnerRefForSecret(
return err
}

secret.OwnerReferences = util.EnsureOwnerRef(
secret.OwnerReferences,
metav1.OwnerReference{
APIVersion: clusterv1.GroupVersion.String(),
Kind: cluster.Kind,
UID: cluster.UID,
Name: cluster.Name,
},
)
err = controllerutil.SetOwnerReference(cluster, secret, cl.Scheme())
if err != nil {
return fmt.Errorf("failed to set owner reference on Secret: %w", err)
}

err = cl.Update(ctx, secret)
if err != nil {
Expand Down

0 comments on commit 6f6d921

Please sign in to comment.