mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 23:23:23 +09:00
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. Alerta builds the resource from exported_instance and deduplicates on environment, resource and event, without the cluster tag. With only the namespace there, two clusters with a stuck namespace of the same name became one Alerta alert, and the resolve from one cluster closed it while the other namespace was still terminating. The resource is now cluster/namespace. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
27 lines
1001 B
Bash
27 lines
1001 B
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
|
VMALERT_TOOL_IMAGE="victoriametrics/vmalert-tool:v1.136.0@sha256:417346d7b6fdb66d8e3984887c2ad114535ec7d983eeef53381b56c776f333f1"
|
|
|
|
@test "namespace deletion alerts pass their vmalert-tool cases" {
|
|
docker info >/dev/null 2>&1 || {
|
|
echo "docker is required to run the cases in $VMALERT_TOOL_IMAGE" >&2
|
|
return 1
|
|
}
|
|
work=$(mktemp -d)
|
|
rc=0
|
|
yq '.spec' "$REPO_ROOT/packages/system/monitoring-agents/alerts/namespace-deletion.yaml" > "$work/rules.yaml" || rc=$?
|
|
cp "$REPO_ROOT/hack/testdata/namespace-deletion-alerts/unittest.yaml" "$work/unittest.yaml" || rc=$?
|
|
if [ "$rc" -eq 0 ]; then
|
|
docker run --rm --network none -v "$work:/w:ro" "$VMALERT_TOOL_IMAGE" \
|
|
unittest --files /w/unittest.yaml > "$work/out" 2>&1 || rc=$?
|
|
cat "$work/out"
|
|
fi
|
|
passed=$(grep -cx 'SUCCESS' "$work/out" 2>/dev/null || true)
|
|
rm -rf "$work"
|
|
[ "$rc" -eq 0 ]
|
|
[ "$passed" -eq 1 ]
|
|
}
|