Skip to content

fix(): Persist VpnKeyRotation owner reference to Kubernetes API server#398

Open
Priyanshubhartistm wants to merge 2 commits into
kubeslice:masterfrom
Priyanshubhartistm:fix/vpnkeyrotation-orphan-cr
Open

fix(): Persist VpnKeyRotation owner reference to Kubernetes API server#398
Priyanshubhartistm wants to merge 2 commits into
kubeslice:masterfrom
Priyanshubhartistm:fix/vpnkeyrotation-orphan-cr

Conversation

@Priyanshubhartistm

Copy link
Copy Markdown

Description

Fixes #396

When VpnKeyRotation has no owner references, controllerutil.SetControllerReference() was called to link it to the parent SliceConfig - but UpdateResource() was never called after. So the owner reference only lived in memory and was never saved to etcd. When SliceConfig gets deleted, Kubernetes GC has no idea these two are related, so VpnKeyRotation stays around as an orphan.

Fix is one call: util.UpdateResource() right after SetControllerReference().

How Has This Been Tested?

  • go build ./... - passes, no errors
  • go test -gcflags=-l ./service - all existing tests pass

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates? No.
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit test cases.

Does this PR introduce a breaking change for other components like worker-operator?

No. Single line added inside an existing nil-guard. No API or schema changes.


SetControllerReference() was only setting the owner reference in memory
but never calling UpdateResource() to persist it to the Kubernetes API
server (etcd). This caused VpnKeyRotation CRs to become orphans after
their parent SliceConfig was deleted, since Kubernetes GC relies on
ownerReferences stored in etcd to perform cascading deletion.

Fix: Add UpdateResource() call immediately after SetControllerReference()
so the owner reference is durably written to the cluster.

Fixes: kubeslice#396
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
- Replace util.Client with client.Client in prepareACSTestContext,
  prepareNamespaceTestContext, and prepareProjectTestContext function
  signatures. util.Client type does not exist; the correct type is
  client.Client from sigs.k8s.io/controller-runtime/pkg/client.

- Add missing client package import to project_service_test.go.

- Remove deprecated ClusterName field from metav1.ObjectMeta struct
  literal in worker_slice_gateway_service_test.go. ClusterName was
  removed from ObjectMeta in k8s API 1.25+.

- Fix namespace_service_test.go mock expectation to include
  Annotations: map[string]string{} to match what the service sets.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@Priyanshubhartistm Priyanshubhartistm force-pushed the fix/vpnkeyrotation-orphan-cr branch from 0384a02 to 8763045 Compare May 24, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SetControllerReference is called but the result is never saved( VpnKeyRotation CRs become orphans)

1 participant