Skip to content

Conversation

@NoaheCampbell
Copy link
Contributor

Description, Motivation and Context

Adds a lint command for preflight and support bundle that will look through provided v1beta2 and v1beta3 specs and give clear syntax errors for anything that is wrong, such as missing fields, incorrect collector/analyzer, and type matching for fields and their values.

There is also a --fix flag that will attempt to fix any syntax errors that do make minimal assumptions, for example it will add missing fields to collectors and analyzers with placeholder values, but it will not try to assume the type of spec it is, preflight or support bundle.

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@NoaheCampbell NoaheCampbell added the type::feature New feature or request label Oct 14, 2025
cursor[bot]

This comment was marked as outdated.

@NoaheCampbell
Copy link
Contributor Author

There are example files in

examples/test-error-messages

which can be run either manually or you can run the go test in pkg/lint/lint_test.go. Running them manually will get you results like the following:

./bin/preflight lint examples/test-error-messages/invalid-collectors-analyzers.yaml

examples/test-error-messages/invalid-collectors-analyzers.yaml:
  ✗ Error (line 15): Unknown analyzer type 'notAnAnalyzer'
    Field: spec.analyzers[0]
  ✗ Error (line 17): Missing required field 'outcomes' for analyzer 'cephStatus'
    Field: spec.analyzers[1].cephStatus.outcomes
  ✗ Error (line 8): Unknown collector type 'notACollector'
    Field: spec.collectors[0]
  ✗ Error (line 10): Missing required field 'namespace' for collector 'ceph'
    Field: spec.collectors[1].ceph.namespace
  ✗ Error (line 12): Expected 'hostCollectors' to be a list
    Field: spec.hostCollectors
  ⚠ Warning (line 5): Some analyzers and collectors are missing docString (recommended for v1beta3)
    Field: spec

And then to test the --fix flag you can simply add --fix to it and you will get the following result for this same example

noah@NoahC-HQ19XY9P3Q troubleshoot % ./bin/preflight lint examples/test-error-messages/invalid-collectors-analyzers.yaml --fix

examples/test-error-messages/invalid-collectors-analyzers.yaml:
  ✗ Error (line 16): Unknown analyzer type 'notAnAnalyzer'
    Field: spec.analyzers[0]
  ✗ Error (line 8): Unknown collector type 'notACollector'
    Field: spec.collectors[0]
  ⚠ Warning (line 5): Some analyzers and collectors are missing docString (recommended for v1beta3)
    Field: spec

Summary: 2 error(s), 1 warning(s) across 1 file(s)

And the changes will be applied to the test file provided. You can make up analyzer/collector names to test it, leave out required fields or make ones that don't exist to see if they will show up in the terminal.

Copy link
Contributor

@bennyyang11 bennyyang11 left a comment

Choose a reason for hiding this comment

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

Tested on my device and looks good to me

@NoaheCampbell NoaheCampbell merged commit 6ffc83d into main Oct 14, 2025
21 checks passed
@NoaheCampbell NoaheCampbell deleted the updated-linter branch October 14, 2025 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type::feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants