Skip to content

CICD-405 · Preview environment expiration ​

Encyclopedia · Preview environments and developer experience · All snippets

Previous · CICD-404 · Next · CICD-406

1. Where it fits ​

  • Placement trusted cleanup controller check.
  • Prerequisites trusted preview controller, disposable environment and scoped identities for external resources.
  • Platforms kubernetes, local-lab.

2. Copy the snippet ​

bash
kubectl get namespaces -l managed-by=preview -o json | jq -r --arg now "$(date -u +%FT%TZ)" '.items[] | select(.metadata.annotations["preview.example.com/expires"] != null and .metadata.annotations["preview.example.com/expires"] < $now) | .metadata.name'

3. How it works ​

The inventory query considers only labeled preview namespaces with a canonical expired timestamp. It emits candidates for cleanup rather than deleting resources itself.

Ownership and expiry jointly qualify a namespace for review.

flowchart TD
  N1["Namespaces labeled as previews"]
  N2{"Expiry before now"}
  N1 --> N2
  N3["Output cleanup candidate"]
  N2 -->|Yes| N3
  N4["Keep out of candidate list"]
  N2 -->|No| N4

4. Verify the result ​

Review canonical UTC timestamps and ownership before applying CICD-277. An expired namespace list is only a deletion candidate list.

Validation syntax-validated (Bash parse). Status definitions.