Skip to content

[Backport release-1.6] feat(monitoring): alert when a namespace stays in Terminating - #5041

Open
europrinter (yankawai) wants to merge 2 commits into
cozystack:release-1.6from
yankawai:backport/namespace-stuck-terminating-alert-1.6
Open

europrinter (yankawai) wants to merge 2 commits into
cozystack:release-1.6from
yankawai:backport/namespace-stuck-terminating-alert-1.6

Conversation

@yankawai

Copy link
Copy Markdown
Contributor

What this PR does

Backport of #5040 to release-1.6.

On release-1.6 kube-state-metrics 2.15.0 with its namespaces collector, the kube-state-metrics scrape, the alerts template, the VMAlert and vm-operator v0.68.4 are the same as on main, and no alert rule there reads kube_namespace_status_phase either. The rule and its test data apply without changes. A second commit drops the load test_helper line from the Bats suite, because release-1.6 has no hack/test_helper.bash and runs hack/*.bats through hack/cozytest.sh, where that line stops the suite with exit 127.

On this branch hack/cozytest.sh hack/namespace-deletion-alerts.bats passes, 5 cases with 11 checks. With the expression replaced by vector(1) == 0 it fails the 4 checks that expect an alert, and each rule change listed in #5040 fails as many checks as on main. I ran every non-e2e hack/*.bats through hack/cozytest.sh, the way make bats-unit-tests runs them here, with Helm 3.17.3 on PATH. 42 of 47 files pass, alert-severity-contract among them with the new alert as warning. The other 5 (cilium-ipam-migration, nightly-mirror_test, overlay-main-images_test, promote-retag_test, promote-rewrite-tags_test) fail the same way on release-1.6 itself in my local environment, macOS with bash 3.2 and BSD sed and awk. helm-unittest 1.1.2 passes the monitoring-agents chart with 2 of 2 tests, and helm template renders the VMRule the same as the file. I have not run the rule in vmalert on a live cluster.

Screenshots

Not a UI change.

Downstream repositories

The same three files as #5040, a new alert file, a Bats suite and its test data. No trigger map entry applies.

Release note

feat(monitoring): new warning alert KubeNamespaceStuckTerminating fires when a namespace has been in phase Terminating for more than 30 minutes.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: cozystack/cozystack/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 352686b8-7ff6-4b09-baf6-db128c33a2e2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added area/monitoring Issues or PRs related to the monitoring stack (vlogs, vmstack, grafana, workloadmonitor) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/feature Categorizes issue or PR as related to a new feature size/L This PR changes 100-499 lines, ignoring generated files labels Oct 21, 2026
A namespace that never finished deleting raised no alert of its own.
A tenant namespace deleted directly, not through its Tenant, stayed in
Terminating for about 28 hours while the finalizer of a Kamaji
TenantControlPlane inside it waited for a DataStore secret after the
tenant etcd was gone. The only signal was HelmReleaseNotReady of the
tenant release, which kept flapping.

kube-state-metrics exports kube_namespace_status_phase with a
Terminating series per namespace that is 1 while it is being deleted.
The rule takes the maximum per cluster and namespace, so the timer
survives kube-state-metrics moving to another node, which changes its
node and pod target labels. Healthy deletions finish in under a minute,
and in about five for a tenant with a Kubernetes cluster, a VM and
Postgres inside, so 30 minutes leaves wide room and still reports a
stuck namespace within the hour.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
(cherry picked from commit 79627dc)
hack/test_helper.bash does not exist on release-1.6, and that branch
runs hack/*.bats through hack/cozytest.sh, which has no load builtin.
With the line kept from main the suite exits 127 before vmalert-tool
runs.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
@yankawai
europrinter (yankawai) force-pushed the backport/namespace-stuck-terminating-alert-1.6 branch from 8c4e212 to b78ea9d Compare October 21, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/monitoring Issues or PRs related to the monitoring stack (vlogs, vmstack, grafana, workloadmonitor) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/feature Categorizes issue or PR as related to a new feature size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant