Skip to content

fix(cli): hand the operator mode's API key Secret to the kates chart - #688

Merged
bmscomp merged 2 commits into
mainfrom
fix/kates-api-key-switch
Nov 17, 2026
Merged

bmscomp merged 2 commits into
mainfrom
fix/kates-api-key-switch

Conversation

@bmscomp

@bmscomp bmscomp commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Problem

kates deploy --kates-mode operator writes the Secret kates-api-key with kubectl apply (applySecret in cli/cmd/deploy_kates_operator.go). Once the Kates resource is deleted, a standalone kates deploy fails at helm upgrade --install kates. The chart renders a Secret of the same name (charts/kates/templates/api-key-secret.yaml), and Helm refuses to install over an object that lacks its ownership metadata:

Error: unable to continue with install: Secret "kates-api-key" in namespace "..." exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; ...

I reproduced this on Kind (Helm 4.3.2) in a scratch namespace, with a Secret written as applySecret writes it.

Fix

Before the standalone Helm install, adoptAPIKeySecret checks kates-api-key in the Kates namespace. If Helm doesn't manage it, the CLI adds app.kubernetes.io/managed-by=Helm and the meta.helm.sh/release-name=kates / meta.helm.sh/release-namespace=<ns> annotations. Helm then adopts the Secret, and the chart's lookup reuses its value, so clients keep their key. When the Secret is absent, or Helm already manages it, nothing changes.

The fix sits in the install path, not in applySecret, so operator-mode installs already made with v1.41.x also switch cleanly.

Tests

  • TestTheOperatorModesAPIKeySecretIsHandedToTheChart covers three cases: no Secret, an operator-mode Secret (adopted), and a Helm-managed Secret (left alone).
  • On Kind I ran the exact kubectl get jsonpath, label and annotate commands, then a Helm install of a chart rendering the same Secret: it reported STATUS: deployed and kept the key keep-me.
  • go vet ./... and go test -p 1 -race -count=1 ./... in cli/ both pass.
  • golangci-lint reports only two pre-existing errcheck findings, both in cmd/mcp_test.go, a file this PR doesn't touch.
  • Not run: a full operator-mode deploy → delete → standalone kates deploy on a cluster.

Docs, second commit: #686 merged with a manual kubectl delete secret kates-api-key in Tutorial 16's switch-back step. This PR removes that step and keeps it only as a note for a CLI of v1.41.2 or older. It also updates Switching Modes in docs/book/kates-operator.md.

bmscomp added a commit that referenced this pull request Nov 17, 2026
kates deploy hands the operator mode's kates-api-key to the kates chart
(#688), so the switch-back step no longer deletes it. A note keeps the
manual step for a CLI of v1.41.2 or older.
An operator-mode deploy writes kates-api-key with kubectl apply. After the
Kates resource is deleted, a standalone kates deploy then failed:
helm refuses to install the chart's Secret over one without its ownership
metadata ("invalid ownership metadata").

Before the standalone helm install, deploy now labels and annotates a
kates-api-key that Helm doesn't manage as release kates's, so Helm adopts
it and the chart's lookup keeps the key clients already hold. A Secret Helm
already manages is left alone.
kates deploy hands the operator mode's kates-api-key to the kates chart
(#688), so the switch-back step no longer deletes it. A note keeps the
manual step for a CLI of v1.41.2 or older.
@bmscomp
bmscomp force-pushed the fix/kates-api-key-switch branch from 5d99851 to ca15aa1 Compare November 17, 2026 01:25
@bmscomp
bmscomp merged commit 72ec967 into main Nov 17, 2026
68 checks passed
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.

1 participant