Skip to content
5 min read Updated

How a YAML List vs Map Difference Crash-Looped My Kyverno Fix

Kyverno's cleanup-controller extraArgs expects a map, not a list, so my leader-election fix crash-looped the pod it was meant to stabilize. How to catch it.


Disclosure: This post contains Amazon affiliate links (marked with *). As an Amazon Associate I earn from qualifying purchases. Buying through them costs you nothing extra.

Kyverno’s cleanup-controller had restarted 337 times in 16 days. Its leader-election lease renewal kept timing out against the API server (the same class of instability that CPU contention causes for etcd), and the single-replica controller shut itself down every time it lost leadership. The fix looked simple: increase leaderElectionRetryPeriod. Instead, it crash-looped the very pod it was meant to stabilize.

The Symptom

Within minutes of the change syncing, the pod from the new ReplicaSet was in CrashLoopBackOff: it started, exited immediately, and Kubernetes kept restarting it.

The Investigation

A crash right at startup usually means the binary is rejecting its flags, and that is what happened here. The binary received --0=--leaderElectionRetryPeriod=10s as a single argument. Kyverno’s binaries parse their arguments with Go’s standard flag package, which splits that at the first =, looks for a flag named 0, and exits with flag provided but not defined: -0 followed by the usage text. That is not a valid argument. It is what the chart template renders when the values have the wrong YAML structure.

The Root Cause: List vs Map

The Helm chart’s cleanupController.extraArgs expects a map, not a list:

# WRONG - list syntax, renders as --0=--leaderElectionRetryPeriod=10s
cleanupController:
  extraArgs:
    - "--leaderElectionRetryPeriod=10s"

# CORRECT - map syntax, renders as --leaderElectionRetryPeriod=10s
cleanupController:
  extraArgs:
    leaderElectionRetryPeriod: "10s"

The cleanup-controller template renders each entry with range $key, $value := .Values.cleanupController.extraArgs and emits --{{ $key }}={{ $value }}. Over a map, that gives the flag name and value. Over a list, Go templates hand range the index as the key and the item as the value, so the first item becomes --0= followed by the whole string. The rendered result:

# What the binary actually receives:
--0=--leaderElectionRetryPeriod=10s

# What it expected:
--leaderElectionRetryPeriod=10s

The binary sees 0 as a flag name, doesn’t recognize it, and exits with a non-zero code. Kubernetes restarts the pod, and the loop begins.

Why This Is a Production Risk

This wasn’t a staging environment. The cleanup-controller executes Kyverno’s CleanupPolicy and ClusterCleanupPolicy resources and the TTL-based deletions driven by the cleanup.kyverno.io/ttl label. If the controller is down, none of that runs.

The fix for leader-election instability caused a worse instability. I caught it within minutes from the new pod’s status and corrected the values on the cluster before the git-side fix landed.

How to Catch This Before It Hits Production

1. Dry-run the Helm template:

helm template kyverno kyverno/kyverno -n kyverno \
  --set cleanupController.extraArgs.leaderElectionRetryPeriod=10s \
  | grep -A5 cleanup-controller

If the rendered YAML shows --0=... in the container args, the structure is wrong.

2. Check the chart’s values.yaml:

helm show values kyverno/kyverno | grep -A10 extraArgs

The chart documents whether extraArgs is a map or list. Trust the chart, not your muscle memory from other Helm charts.

3. Check the pod right after the rollout:

kubectl get pods -n kyverno -l app.kubernetes.io/name=kyverno-cleanup-controller

If it shows CrashLoopBackOff within the first minute, the flags are wrong.

The Fix

# kubernetes/system/kyverno/application.yml
cleanupController:
  extraArgs:
    leaderElectionRetryPeriod: "10s"

A one-line change. The pod started cleanly and the crash loop stopped.

The Pattern

The real gotcha is that charts disagree. extraArgs is one of the most common value names in the Helm ecosystem, and its type depends on the chart:

ChartFieldTypeExample
KyvernocleanupController.extraArgsmapleaderElectionRetryPeriod: "10s"
cert-managerextraArgslist- --dns01-recursive-nameservers-only
Argo CD (argo-helm)server.extraArgslist- --insecure
Prometheus (prometheus-community)server.extraArgsmaplog.level: debug

Muscle memory from cert-manager or Argo CD is exactly what produces the list syntax that breaks Kyverno. Check the chart’s default ({} or []) in values.yaml, and when in doubt, helm template shows exactly what the binary receives.

Further reading: Designing Data-Intensive Applications by Martin Kleppmann* covers leases, process pauses, and timeouts in distributed systems, which is the mechanism behind leader-election failures under load.


A Kyverno controller only does its job while it is running. Render your Helm values with helm template before they reach the cluster, and check the pod status right after every rollout.

Was this helpful?
Share
DW

David Woitzik

Hybrid Cloud Engineer

I work mostly with Azure, Terraform, and Zero-Trust network design, and publish the Terraform templates and write-ups I wanted when I was solving the same problems.

Keep Reading

More Like This in Your Inbox

New Terraform modules and articles by email. No spam.