## What this PR does On a cluster running v1.6.5 a tenant namespace that was deleted directly, not through the Tenant app, stayed in `Terminating` for about 28 hours, held by the Kamaji finalizers described in #5002. Nothing alerted on the namespace itself. The only signal was `HelmReleaseNotReady` of the tenant release, which kept flapping. kube-state-metrics already exports `kube_namespace_status_phase` and `dashboards/main/capacity-planning.json` reads it, but no alert rule in the repo does. This adds `KubeNamespaceStuckTerminating`, a warning in a new `namespace-deletion` group under `packages/system/monitoring-agents/alerts/`. It fires when `max by (cluster, namespace) (kube_namespace_status_phase{job="kube-state-metrics", phase="Terminating"}) == 1` has held for 30 minutes. kube-state-metrics exports a `Terminating` series for every namespace, 0 while the namespace is active and 1 while it is being deleted ([namespace.go#L109-L135](https://github.com/kubernetes/kube-state-metrics/blob/v2.15.0/internal/store/namespace.go#L109-L135)). The scrape adds the node and pod of the kube-state-metrics pod as target labels, so the rule groups by cluster and namespace and its timer keeps running through a kube-state-metrics rollout to another node. A gap in the series, for example while kube-state-metrics is down, starts the 30 minutes over. The description names the namespace and the cluster and points at the namespace status conditions, which list the remaining resource types and finalizers ([status_condition_utils.go#L101-L140](https://github.com/kubernetes/kubernetes/blob/v1.33.12/pkg/controller/namespace/deletion/status_condition_utils.go#L101-L140)). Why 30 minutes. Healthy tenant deletions we watched on current versions took under a minute from the delete request until the namespace was gone, 61 of 61, and about 5 minutes for a tenant with a Kubernetes cluster, a VM and Postgres inside. The namespace itself spent under a minute in `Terminating` in every one of them. 30 minutes leaves wide room and still reports a stuck namespace within the hour. `hack/namespace-deletion-alerts.bats` replays `.spec` of the VMRule through `vmalert-tool` v1.136.0 pinned by digest, the same harness as #4963, #4985 and #4993. `hack/testdata/namespace-deletion-alerts/unittest.yaml` has 5 cases with 11 checks. A namespace in `Terminating` is quiet at 29 minutes and fires at 35, with labels and annotations pinned. A namespace deleted after 20 minutes in `Terminating` stays quiet at 19, 35 and 60 minutes, and an active namespace stays quiet. When kube-state-metrics moves to another node 15 minutes in, the alert still fires at 31 minutes. The same namespace name in two clusters gives one alert per cluster, each with its own timer. ```console $ bats hack/namespace-deletion-alerts.bats 1..1 ok 1 namespace deletion alerts pass their vmalert-tool cases ``` With the expression replaced by `vector(1) == 0` the suite prints `not ok 1` and vmalert-tool fails the 4 checks that expect an alert. On main, where the rule file does not exist, the suite fails too. Each of the following rule changes fails at least one check. They are `for: 15m`, `for: 45m`, no `== 1`, `sum by` instead of `max by`, which only the kube-state-metrics move catches, no `cluster` in the grouping, `phase="Active"`, no aggregation, another severity and another description. With Bats 1.14.0 at the commit CI pins and Helm 3.17.3 on `PATH`, 18 suites pass with 325 of 325 tests, the new one together with `alert-severity-contract`, `bats-strict-setup`, `bats-runner-coverage`, `bats-runner-contract`, `unit-test-parallelism`, `image-pin-consistency` and `check-commit-trailers` among others. The severity contract lists the new alert as `warning`. helm-unittest 1.1.2 passes the monitoring-agents chart with 19 of 19 tests, and `helm template` renders the VMRule the same as the file. Like the migration suites, the new suite needs docker. I have not run the rule in vmalert on a live cluster. The release-1.6 backport is a separate PR with one more commit that drops the `load test_helper` line, because release-1.6 runs `hack/*.bats` through `hack/cozytest.sh`. ### Screenshots Not a UI change. ### Downstream repositories A new alert file under `packages/system/monitoring-agents/alerts/`, a Bats suite under `hack/` and its test data. No values, schema, README, image or `ApplicationDefinition` change, and the website does not list platform alerts by name, so no trigger map entry applies. - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note feat(monitoring): new warning alert KubeNamespaceStuckTerminating fires when a namespace has been in phase Terminating for more than 30 minutes. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **New Features** - Added an alert for Kubernetes namespaces that remain in the `Terminating` phase for more than 30 minutes. - Alerts identify the affected cluster and namespace and note that remaining finalizers may be preventing deletion. - **Tests** - Added coverage for deletion timing, active namespaces, node changes during termination, and identically named namespaces across clusters. Test cases verify expected alert labels and annotations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Cozystack
Cozystack is a free and open-source platform and framework for building clouds.
Cozystack is a CNCF Sandbox project that was originally built and sponsored by Ænix.
With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.
Use Cozystack to build your own cloud or provide a cost-effective development environment.
Use-Cases
-
Using Cozystack to build a public cloud
You can use Cozystack as a backend for a public cloud -
Using Cozystack to build a private cloud
You can use Cozystack as a platform to build a private cloud powered by Infrastructure-as-Code approach -
Using Cozystack to build your own platform
You can install only the Cozystack components you need on an existing Kubernetes cluster
Documentation
The documentation is located on the cozystack.io website.
Read the Getting Started section for a quick start.
If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.
Versioning
Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.
Contributions
Contributions are highly appreciated and very welcomed!
In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.
You are welcome to take on the fix yourself. Commits are used to generate the changelog, and their author will be referenced in it.
If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.
Community
You are welcome to join us in #cozystack, on either CNCF Slack (get an invite) or Kubernetes Slack (get an invite), in our Telegram group, and at our community meetings. Add them to your Google Calendar or iCal for convenience.
Project documents
| Document | What it covers |
|---|---|
| Governance | How decisions are made and who makes them |
| Contributor Ladder | How to grow from contributor to maintainer |
| Maintainers | Who maintains the project |
| Code of Conduct | What we expect of each other |
| Security Policy | Reporting a vulnerability, and which releases get fixes |
| Adopters | Who runs Cozystack in production |
| Roadmap | Where the project is going |
License
Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.
Commercial Support
A list of companies providing commercial support for this project can be found on official site.
