Updating IngressClassName in Values
For each <project>/qualif/values.yaml, ensure the result contains:
YAMLingresses: ingressClassName: traefik
Do this with yq (eval in-place, -i), never manual text editing — it preserves YAML structure and comments better and avoids indentation mistakes.
Detect OS first:
- Windows → binary is
yq.exe - Linux/Mac → binary is
yq
Bash# Linux/Mac example for one file yq -i '.ingresses.ingressClassName = "traefik"' path/to/qualif/values.yaml
This single yq expression handles all three cases described below because yq's = assignment creates missing keys (ingresses, then ingressClassName) and overwrites existing scalar values — no need for separate branches in yq itself. Still, verify per-file logic explicitly (see Workflow) so you can log what changed.
Progress:
- Step 1: Detect OS, pick
yqbinary (yqvsyq.exe) - Step 2: Find all
*/qualif/values.yamlfiles under project root - Step 3: For each file, inspect current state of
ingresses/ingressClassName - Step 4: Apply the correct fix (add block / add key / fix value)
- Step 5: Validate result and log a summary per file
Step 1 — Pick the binary
Bashif [[ "$OSTYPE" == "msys" || "$OS" == "Windows_NT" ]]; then YQ=yq.exe else YQ=yq fi
Step 2 — Enumerate target files
Bashfind . -type d -name qualif -exec test -f {}/values.yaml \; -print # or directly build file list: find . -path "*/qualif/values.yaml"
Step 3 — Inspect before modifying (for correct logging / decision)
Bash$YQ e '.ingresses' file.yaml # null if missing $YQ e '.ingresses.ingressClassName' file.yaml # null if missing key
Three cases:
- No
ingresseskey at all → add the whole block:Bash$YQ -i '.ingresses.ingressClassName = "traefik"' file.yaml ingressesexists but noingressClassName→ add key under existing block (same command works, yq merges into existing map without clobbering sibling keys):Bash$YQ -i '.ingresses.ingressClassName = "traefik"' file.yamlingresses.ingressClassNameexists but wrong value (e.g.nginx) → overwrite:Bash$YQ -i '.ingresses.ingressClassName = "traefik"' file.yaml
All three cases reduce to the same idempotent yq command — this is the key insight, use it as the single implementation, but keep the pre-check (Step 3) to report what was changed vs already-correct.
Step 4 — Apply and log
Bashfor f in $(find . -path "*/qualif/values.yaml"); do before=$($YQ e '.ingresses.ingressClassName' "$f") $YQ -i '.ingresses.ingressClassName = "traefik"' "$f" after=$($YQ e '.ingresses.ingressClassName' "$f") echo "$f: before=[$before] after=[$after]" done
Step 5 — Validate
Bash$YQ e '.ingresses.ingressClassName' file.yaml # must print: traefik
Optionally validate the whole file still parses:
Bash$YQ e '.' file.yaml > /dev/null || echo "INVALID YAML: $file"
Example 1 — key missing entirely
Input (values.yaml):
YAMLreplicaCount: 2 image: repository: myapp
Output:
YAMLreplicaCount: 2 image: repository: myapp ingresses: ingressClassName: traefik
Example 2 — ingresses present, ingressClassName missing
Input:
YAMLingresses: enabled: true host: myapp.example.com
Output:
YAMLingresses: enabled: true host: myapp.example.com ingressClassName: traefik
Example 3 — wrong value present Input:
YAMLingresses: ingressClassName: nginx
Output:
YAMLingresses: ingressClassName: traefik
- Always use
yq -i(in-place) rather than sed/regex — YAML structure/indentation stays valid. - Run a dry-run pass first (print
before/afterwithout-i) on a few files to confirm behavior before bulk-applying. - Back up files first if not under git, e.g.
cp file.yaml file.yaml.bak, or rely ongit diffafter the run to review changes. - Confirm
yqversion is Mike Farah's Goyq(v4+), since syntax (.a.b = "x") differs from Pythonyq/jqwrapper. - Process files in a loop with clear per-file logging so partial failures are visible.
- Don't use plain string replacement/sed for nested YAML — it breaks on differing indentation or when
ingressesblock already has other sibling keys. - Don't assume
ingressesis a list — here it's treated as a map (singular ingress config with a class name), notingresses: []. - Don't forget the OS-specific binary name (
yqvsyq.exe); hardcoding one breaks cross-platform runs. - Don't skip validation — a malformed yq expression can silently produce
nullor corrupt the file structure.