Skip to content

feat(tts-audio): prune objects the repo no longer declares - #285

Merged
ngeorger merged 1 commit into
mainfrom
feat/tts-audio-prune-stale
Nov 27, 2026
Merged

ngeorger merged 1 commit into
mainfrom
feat/tts-audio-prune-stale

Conversation

@sredevopsorgagents

@sredevopsorgagents sredevopsorgagents commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

kubectl apply is a create-or-update verb: it never removes an object whose name changed in the repo. That already happened here.

The drift

Renaming allow-webhook-kubernetes-api → allow-kubernetes-api-egress (in #283) left both NetworkPolicies in the cluster:

live:
  allow-kubernetes-api-egress    ← new, matches webhook + backfill
  allow-webhook-kubernetes-api   ← stale, still live, still matches every webhook pod

For a NetworkPolicy, "still there" means "still permitting". The stale rule silently widened egress to the API server for every webhook pod — exactly the kind of drift that never shows up as an error.

Verified against the live cluster: the repo declares 4 NetworkPolicies, the cluster has 5.

The fix

make prune compares the rendered manifests with the labelled objects in the cluster and lists what is no longer declared.

  • Dry run by default. CONFIRM=1 deletes.
  • Only kinds this repo owns: networkpolicy httproute serviceaccount role rolebinding poddisruptionbudget horizontalpodautoscaler service configmap deployment.
  • Only objects labelled app.kubernetes.io/part-of=tts-audio, so anything foreign is invisible to it.
  • Never touches secret (created by make secret), job (one-off history) or namespace.

Run against the live cluster it reports exactly one object and nothing else:

prune: 1 object(s) in the cluster are no longer declared:
  - networkpolicy/allow-webhook-kubernetes-api (namespace tts-audio)

prune: dry run. Re-run with CONFIRM=1 to delete them.

make test asserts it stays dry without confirmation.

After merging

make prune TAG=<sha> TTS_HOST=tts-audio.sredevops.org \
  GATEWAY_NAME=tts-audio-gateway GATEWAY_NAMESPACE=kube-system   # dry run
make prune ... CONFIRM=1

Gates

deploy/tts-audio/test.sh ✅ · yarn verify ✅

`kubectl apply` is create-or-update, so renaming a resource in the repo leaves
the old object running forever. That already happened: renaming
`allow-webhook-kubernetes-api` to `allow-kubernetes-api-egress` left both
NetworkPolicies in the cluster, and the stale one still matches every webhook pod
and still permits egress to the API server. For a NetworkPolicy, "still there"
means "still permitting".

- `make prune` compares the rendered manifests with the labelled objects in the
  cluster and lists what is no longer declared. It is a **dry run by default**;
  `CONFIRM=1` deletes.
- It only considers kinds this repo owns and only objects labelled
  `app.kubernetes.io/part-of=tts-audio`, so the Secret (created by `make
  secret`), Jobs (one-off history), Namespaces and anything foreign are never
  touched.
- `make test` asserts it stays dry without confirmation.

Run against the live cluster, it reports exactly one object — the orphaned
networkpolicy and nothing else:

    prune: 1 object(s) in the cluster are no longer declared:
      - networkpolicy/allow-webhook-kubernetes-api (namespace tts-audio)
@ngeorger
ngeorger merged commit aee5954 into main Nov 27, 2026
6 checks passed
@ngeorger
ngeorger deleted the feat/tts-audio-prune-stale branch November 27, 2026 19:20
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.

2 participants