Updating IngressClassName in Values YAML
Bash# Find all target files first find . -path "*/qualif/values.yaml"
For each match, apply this logic:
YAML# Case 1: no "ingresses" key at all -> add block ingresses: ingressClassName: traefik # Case 2: "ingresses" exists but no "ingressClassName" under it -> add key ingresses: someOtherField: value ingressClassName: traefik # <-- added # Case 3: "ingresses.ingressClassName" exists -> force value to traefik ingresses: ingressClassName: traefik # <-- overwritten if it was e.g. nginx
Note: the task description initially says default to nginx, but later clarifies the target value must always end up as traefik. Treat traefik as the single desired final value in all cases — this resolves the contradiction. Confirm this interpretation with the user before a destructive bulk run if any ambiguity remains in their actual repo.
Progress:
- Step 1: Discover all
*/qualif/values.yamlfiles in the project tree - Step 2: Parse each file as YAML (preserve comments/formatting if possible)
- Step 3: Inspect for
ingresseskey - Step 4: Inspect for
ingresses.ingressClassNamekey - Step 5: Apply correct mutation (add block / add key / overwrite value)
- Step 6: Write file back, preserving existing indentation style and other keys untouched
- Step 7: Produce a summary report (file path, action taken: added-block / added-key / overwritten / already-correct)
- Step 8: Diff-review before committing
Step-by-step detail
-
Locate files
Bashfind . -type d -name qualif -exec test -f {}/values.yaml \; -print -
Read and check structure — use a YAML-aware tool (
yq, or a script withruamel.yamlin Python to preserve comments), not naive text search. Naive grep/sed risks corrupting indentation or missing nested keys.Bashyq e '.ingresses' qualif/values.yaml yq e '.ingresses.ingressClassName' qualif/values.yaml -
Decision tree per file:
ingressesisnull→ insert whole block:Bashyq e -i '.ingresses.ingressClassName = "traefik"' qualif/values.yamlingressesexists,ingresses.ingressClassNameisnull→ add key only (sameyqcommand above works for both cases sinceyqcreates missing paths).ingresses.ingressClassNameexists but differs fromtraefik→ overwrite:Bashyq e -i '.ingresses.ingressClassName = "traefik"' qualif/values.yaml- Already
traefik→ skip, log as no-op.
-
Log every action to a report file
ingressclass-update-report.txt:./service-a/qualif/values.yaml: added-block ./service-b/qualif/values.yaml: added-key ./service-c/qualif/values.yaml: overwritten (was: nginx) ./service-d/qualif/values.yaml: already-correct -
Review diffs with
git diffbefore committing, especially for files where indentation might have shifted.
Example 1 — no ingresses key
Input (service-a/qualif/values.yaml):
YAMLreplicaCount: 2 image: repository: my-app tag: latest
Output:
YAMLreplicaCount: 2 image: repository: my-app tag: latest ingresses: ingressClassName: traefik
Example 2 — ingresses present, no ingressClassName
Input:
YAMLingresses: enabled: true host: app.example.com
Output:
YAMLingresses: enabled: true host: app.example.com ingressClassName: traefik
Example 3 — ingressClassName present with wrong value
Input:
YAMLingresses: ingressClassName: nginx host: app.example.com
Output:
YAMLingresses: ingressClassName: traefik host: app.example.com
Example 4 — already correct
Input:
YAMLingresses: ingressClassName: traefik
Output: unchanged, logged as already-correct.
- Use a real YAML parser/editor (
yq,ruamel.yaml) — never blind string replace, since key names likeingressClassNamecould appear in comments or unrelated blocks. - Always run on a git-tracked working tree so changes are reviewable via
git diffand revertible. - Do a dry-run first: print planned changes without writing, then apply after confirmation.
- Batch-process with a script rather than manually editing each file — reduces human error across many folders.
- Keep the per-file action log; it's essential for auditing a bulk change across an unknown number of services.
- Preserve key ordering and existing comments where the tooling allows (
yqin place-edit mode generally preserves comments; naive re-dump of parsed YAML often does not).
- Don't use
sed/regex replace on YAML — breaks on differing indentation, duplicate key names elsewhere in the file, or multi-document files. - Don't assume every project folder actually has a
qualifsubfolder — skip and log missing ones instead of erroring out the whole batch. - Don't overwrite unrelated sibling keys under
ingresses— only touchingressClassName. - Don't forget files where
ingressesis defined as an empty value (ingresses:with nothing under it) — must still correctly nest the new key rather than create a duplicate top-levelingressesblock. - Don't commit without reviewing the diff — bulk YAML tools can occasionally reformat unrelated parts of the file (quote styles, blank lines).