Skip to content

[dmt] validate duplicate yaml keys#432

Open
diyliv wants to merge 3 commits into
mainfrom
fix/module-yaml-strict-unmarshal
Open

[dmt] validate duplicate yaml keys#432
diyliv wants to merge 3 commits into
mainfrom
fix/module-yaml-strict-unmarshal

Conversation

@diyliv

@diyliv diyliv commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use yaml.UnmarshalStrict for module.yaml and Chart.yaml parsing: replaces yaml.Unmarshal with yaml.UnmarshalStrict in CheckDefinitionFile (linter rule), ParseModuleConfigFile, and ParseChartFile.
  • Add test for duplicate YAML keys: new TestCheckDefinitionFile_DuplicateKeys reproduces the real bug where descriptions.en was defined twice.
  • Affected files: pkg/linters/module/rules/module_yaml.go, internal/module/module.go, pkg/linters/module/rules/module_yaml_test.go

Context

module.yaml with duplicate keys (e.g. en: defined twice under descriptions:) silently passed DMT validation because yaml.Unmarshal drops duplicates by taking the last value. However, the Deckhouse controller uses strict parsing and crashes at runtime:

{"level":"error","msg":"run","error":"start deckhouse controller: ... parse module definition ... yaml: unmarshal errors:\n  line 5: mapping key \"en\" already defined at line 4"}

sigs.k8s.io/yaml UnmarshalStrict was already used elsewhere in the codebase (controller rendering, openapi parsing, values, oss.yaml) but not for module.yaml. This aligns the parsing to strict everywhere.

Example

Before (duplicate keys silently accepted):

name: state-snapshotter
stage: "Preview"
descriptions:
  en: "State snapshotter module"
  en: "Модуль State snapshotter"

→ dmt lint passes ✗

After (duplicate keys caught):

Error: definition-file: Cannot parse file "module.yaml": ...

→ dmt lint fails ✓

@diyliv diyliv changed the title validate duplicate yaml keys [dmt] validate duplicate yaml keys Jul 17, 2026
@diyliv
diyliv marked this pull request as draft July 17, 2026 09:20
@diyliv diyliv self-assigned this Jul 17, 2026
@diyliv diyliv added bug Something isn't working go Pull requests that update go code labels Jul 17, 2026
@diyliv
diyliv force-pushed the fix/module-yaml-strict-unmarshal branch 3 times, most recently from ced7d3a to db80f03 Compare July 17, 2026 09:28
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv
diyliv force-pushed the fix/module-yaml-strict-unmarshal branch from db80f03 to 415b084 Compare July 17, 2026 09:31
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv
diyliv marked this pull request as ready for review July 17, 2026 09:44
@diyliv
diyliv marked this pull request as draft July 17, 2026 14:03
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv
diyliv marked this pull request as ready for review July 19, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant