Skip to content

Fix invalid config JSON and enforce canonical config format#1318

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes:masterfrom
hakman:fix-config-json-trailing-commas
Jul 22, 2026
Merged

Fix invalid config JSON and enforce canonical config format#1318
kubernetes-prow[bot] merged 1 commit into
kubernetes:masterfrom
hakman:fix-config-json-trailing-commas

Conversation

@hakman

@hakman hakman commented Jul 13, 2026

Copy link
Copy Markdown
Member

config/disk-log-message-filelog.json contained trailing commas and no trailing newline, so it could not be parsed by encoding/json and NPD would fail to start when configured with it.

This PR:

  • Fixes the invalid JSON.
  • Adds TestShippedConfigs, which verifies that every shipped JSON config under config/ — top level and one directory down (e.g. config/exporter, config/guestosconfig) — parses (catching trailing commas, UTF-8 BOMs and other syntax errors) and is in the canonical format (2-space indent, trailing newline), showing a diff on failure.
  • Adds make fmt-configs to rewrite nonconforming files in place (UPDATE_EXPECTED=y).
  • Normalizes the existing config files to the canonical format (whitespace-only changes).

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 13, 2026
@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 13, 2026
@hakman
hakman force-pushed the fix-config-json-trailing-commas branch from cef4e2d to c297b25 Compare July 13, 2026 14:26
@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 13, 2026
@hakman
hakman force-pushed the fix-config-json-trailing-commas branch from c297b25 to 7b2d3e7 Compare July 13, 2026 14:27
@hakman hakman changed the title Fix invalid JSON in disk-log-message-filelog.json Fix invalid JSON in disk-log-message-filelog.json and enforce config format Jul 13, 2026
@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2026
@hakman
hakman force-pushed the fix-config-json-trailing-commas branch from 7b2d3e7 to c96c103 Compare July 15, 2026 11:01
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2026
@hakman hakman changed the title Fix invalid JSON in disk-log-message-filelog.json and enforce config format Fix invalid config JSON and enforce canonical config format Jul 15, 2026
// that would make NPD fail to start with the config. The format check keeps diffs in PRs minimal.
// Run `make fmt-configs` to rewrite nonconforming files in the canonical format.
func TestShippedConfigs(t *testing.T) {
configs, err := filepath.Glob(filepath.Join("..", "..", "config", "*.json"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't find config/exporter/stackdriver-exporter.json and config/guestosconfig/known-modules.json. The stackdriver exporter config can crash NPD on startup if the config is not correctly formatted, so it's worth catching here. We may need a second glob for config/*/*.json.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch.

config/disk-log-message-filelog.json contained trailing commas and no
trailing newline, so it could not be parsed by encoding/json and NPD
would fail to start when configured with it.

- Fix the invalid JSON
- Add TestShippedConfigs, which verifies that every shipped JSON config
  under config/ (top level and one directory down) parses (catching
  trailing commas, UTF-8 BOMs and other syntax errors) and is in the
  canonical format (2-space indent, trailing newline), showing a diff on
  failure
- Add `make fmt-configs` to rewrite nonconforming files in place
  (UPDATE_EXPECTED=y)
- Normalize the existing config files to the canonical format
  (whitespace-only changes)
@hakman
hakman force-pushed the fix-config-json-trailing-commas branch from c96c103 to 87dfadb Compare July 22, 2026 04:58
@hakman

hakman commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/cc @wangzhen127 @ameukam

@kubernetes-prow
kubernetes-prow Bot requested review from ameukam and wangzhen127 July 22, 2026 06:15
@ameukam

ameukam commented Jul 22, 2026

Copy link
Copy Markdown
Member

/lgtm

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 22, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ameukam, hakman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow
kubernetes-prow Bot merged commit 4cc149d into kubernetes:master Jul 22, 2026
15 checks passed
@hakman
hakman deleted the fix-config-json-trailing-commas branch July 22, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants