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 was restarting every few hours. Its leader-election lease kept expiring under load (the same class of instability that CPU contention causes for etcd), so the controller lost its lock and a new leader took over, leaving a brief gap in cleanup processing. The fix looked simple: increase leaderElectionRetryPeriod. Instead, it crash-looped the very pod it was meant to stabilize.

The Symptom

cleanup-controller-7f8b9c4d6-xk2p4   0/1     CrashLoopBackOff   3 (42s ago)

The pod started, crashed immediately, and Kubernetes restarted it: three crashes in under two minutes, with the cleanup controller showing as unavailable.

The Investigation

A crash right at startup usually means the binary is rejecting its flags. The pod’s logs confirmed it:

Error: unknown flag: --0=--leaderElectionRetryPeriod=10s

The binary received --0=--leaderElectionRetryPeriod=10s as a single flag. 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 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. While it is down, none of that runs, and a crash-looping pod also keeps churning the leader lock it was supposed to stabilize.

The fix for leader-election instability caused a worse instability. The cleanup-controller restarted three times before I caught it, and scheduled cleanups did not run in that window.

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.