Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

You are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?

AdvancedScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Event-driven reconciliation; watches can drop and expire.

What I'd do →

  1. Consider whether a mutating admission policy or Kyverno rule does this declaratively; usually it does.
  2. If code is needed, use kopf (handles watches, retries, and resumption) or a watch loop that lists first, reconciles all, then watches from the list's resourceVersion.
  3. Handle 410 Gone by re-listing, and reconnect on timeouts.
  4. Patch idempotently (only if the label is missing).
  5. Run in-cluster with a service account allowed only get, list, watch, patch on namespaces.

Why → Level-triggered reconciliation (look at all current state) survives missed events.

Interview tip → Say "level-triggered, not edge-triggered" and mention 410 Gone.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation