Install all Helm chart resources into the release namespace
What type of PR is this?
/kind bug
What this PR does / why we need it:
helm install -n <ns> only moved part of Kelos into <ns>. The controller manager and its supporting resources were hardcoded to kelos-system, and the chart always created Namespace/kelos-system.
This PR makes every namespaced resource follow the release namespace:
- Hand-written templates: the controller Deployment,
kelos-controllerServiceAccount,kelos-webhookService, Certificate (includingdnsNames), Issuer, leader-election Role/RoleBinding,kelos-controller-rolebindingsubject, and the telemetry CronJob use{{ .Release.Namespace }}. The control-plane PodMonitor selects only the release namespace. - Generated files:
hack/update-install-manifest.shtemplates the webhook Service namespace andcert-manager.io/inject-ca-frominvalidating-webhook.yamland in the subchart CRDs that carry conversion webhooks. The staticinstall-crd.yaml(applied bykelos install) keepskelos-system. Namespaceobject: rendered only when the release namespace iskelos-system, sokelos installand existingkelos-systemreleases keep owning it. Other namespaces come from--create-namespaceor the user.- Telemetry: the installation ID ConfigMap namespace is injected through a new
--telemetry-namespacecontroller flag, set by the CronJob to the release namespace. It is required with--telemetry-report. kelos install/kelos uninstall: no behavior change; they still render intokelos-system.- Conversion guard: with
crds.install=false, the chart looks uptasks.kelos.devand fails if its conversion webhook names a namespace other than the release namespace. This stops an upgrade from moving thekelos-webhookService away from CRDs the release does not render (CRDs fromkelos install, or CRDs kept bycrds.keepduring phase 1 of a two-phase upgrade).lookupfinds nothing underhelm templateandkelos install, so offline rendering is unaffected; tools that render withhelm template(such as Argo CD) skip the check, andcrds.install=falsereleases needgetoncustomresourcedefinitions. The failure message points to "Release Namespace" in the chart README. - Docs: chart README ("Release Namespace" section with the guard and a migration guide for releases that own
kelos-systemfrom another namespace; the Option 2 CRD adoption loop now liststaskpipelines.kelos.devandwebhookgateways.kelos.dev, which the chart also renders), thepodMonitor.enabledrow indocs/reference.md, and the troubleshooting skill. - Integration suite:
test/integration/suite_test.gorenders the chart'sValidatingWebhookConfigurationfor envtest instead of readingtemplates/validating-webhook.yaml, which is no longer plain YAML.
Which issue(s) this PR is related to:
Fixes #1816
Special notes for your reviewer:
Not waiting on #1725. The issue marks this as blocked on #1725 because of the CRD conversion webhook. This PR templates the conversion clientConfig.service.namespace and CA annotation in the subchart CRDs, so Helm-rendered CRDs (crds.install=true) work in any namespace. For CRDs the release does not render, the conversion guard refuses an install or upgrade that would leave them pointing at a namespace without the webhook, and the README migration guide covers the one-phase crds.install=true upgrade (adopting outside-managed CRDs first). Once #1725 removes conversion, the guard becomes a no-op (CRDs without a conversion webhook pass) and can be dropped along with the README conversion notes. #1725 will need a small rebase over hack/update-install-manifest.sh, the subchart CRDs, webhook.yaml, render_test.go, and the README.
Decision needed: kelos-system deletion on upgrade. Existing releases installed with -n <other> own Namespace/kelos-system. Upgrading them stops rendering it, so Helm deletes kelos-system and anything in it, and their telemetry installation ID is regenerated. This follows the approach proposed in the issue. Operators who want to keep the namespace can run kubectl annotate namespace kelos-system helm.sh/resource-policy=keep before upgrading; Helm checks the live object's annotation before deleting it (pkg/kube/client.go in Helm v3.20.1). The README and release note document this opt-out.
Verification
make verify,make test, andmake test-integrationpass.- New
TestRender_ReleaseNamespacerenders intokelos-systemandkelosand checks namespaced objects, ServiceAccount binding subjects, CertificatednsNames, webhook/CRD conversion service namespaces, CA annotations, the telemetry flag, the PodMonitor selector, and that the Namespace object is rendered only forkelos-system. Reverting the template changes makes it fail. - Helm v3.20 against an envtest API server (Kubernetes 1.31) with cert-manager CRDs:
- fresh
helm install -n team-b --create-namespace --set crds.install=true: deployed; all 11 namespaced objects inteam-b; nokelos-systemnamespace. -n kelos-systemrelease on the previous chart upgraded to this chart:Namespace/kelos-systemkept (same UID, Active).-n team-arelease on the previous chart upgraded to this chart: controller, Service, and Certificate move toteam-a;kelos-systemis deleted, as described above.-n team-arelease on the previous chart with Helm-owned CRDs: phase 1 (crds.install=false) is refused by the conversion guard with nothing applied; afterkubectl annotate namespace kelos-system helm.sh/resource-policy=keep, a singlecrds.install=trueupgrade moves the CRD conversion toteam-aand keepskelos-system; a later phase 1 upgrade passes the guard.
- fresh
- New
TestRender_CRDConversionNamespaceGuardrenders through a fakelookupclient and covers the rejection plus no live CRD, a CRD without conversion, matching namespaces, akelos-systemrelease, andcrds.install=true.
Pre-existing, not changed here: on main, a first helm install -n kelos-system --create-namespace fails with Helm v3.20 (namespaces "kelos-system" already exists) because both Helm and the chart create the namespace; a retry succeeds as an upgrade. The behavior for kelos-system releases is unchanged by this PR.
Does this PR introduce a user-facing change?
The Helm chart now installs the controller manager, its webhook Service, Certificate, Issuer, leader-election RBAC, and the telemetry CronJob into the Helm release namespace instead of always using `kelos-system`. The chart renders `Namespace/kelos-system` only when the release namespace is `kelos-system`; other release namespaces must already exist or be created with `--create-namespace`. Releases installed into `kelos-system` and `kelos install` are unaffected.
Action required for releases installed into a namespace other than `kelos-system`: the upgrade moves these resources into the release namespace and deletes the `kelos-system` namespace, including anything else in it, unless you first run `kubectl annotate namespace kelos-system helm.sh/resource-policy=keep`. The telemetry installation ID is regenerated. Upgrade in one step with `--set crds.install=true` instead of the two-phase flow; if the CRDs are managed outside Helm, adopt them into the release first. With `crds.install=false`, installs and upgrades now fail when the existing `tasks.kelos.dev` CRD sends conversion requests to a namespace other than the release namespace. See "Release Namespace" in the chart README.
š¤ Generated with Claude Code
Summary by cubic
Every namespaced Helm chart resource now follows the release namespace instead of hardcoding kelos-system, so helm install -n <ns> no longer splits Kelos across two namespaces.
- The controller Deployment, ServiceAccount, webhook Service, Certificate, Issuer, leader-election RBAC, and telemetry CronJob use
{{ .Release.Namespace }}, as do the webhook Service and CA annotations in the validating webhook and in the subchart CRDs. Namespace/kelos-systemis rendered only forkelos-systemreleases, sokelos installkeeps owning it; other namespaces come from--create-namespaceor the user.- The telemetry CronJob passes its namespace through the new required
--telemetry-namespaceflag. - With
crds.install=false, the chart looks uptasks.kelos.devand fails if its conversion webhook names a namespace other than the release namespace;lookupfinds nothing underhelm template, so offline rendering is unaffected. - The README documents the migration path and the CRD adoption loop now covers every CRD the chart renders.
- The integration suite renders the chart and hands envtest the resulting ValidatingWebhookConfiguration, since the template is no longer plain YAML.
kelos installandkelos uninstallare unchanged.
Migration
- Upgrading a release in another namespace moves these resources into the release namespace and deletes
kelos-system, including anything else in it; the telemetry installation ID is regenerated. Annotate the namespace withhelm.sh/resource-policy=keepto retain it. - Upgrade such a release once with
crds.install=true, adopting outside-managed CRDs into Helm first; the two-phase flow is not supported for this upgrade.