Skip to content

fix(autodiscovery/helmfile): error on invalid ignore spec#7620

Merged
olblak merged 1 commit intoupdatecli:mainfrom
railgun-0402:fix/7461-helmfile-invalid-ignore-spec
Jan 28, 2026
Merged

fix(autodiscovery/helmfile): error on invalid ignore spec#7620
olblak merged 1 commit intoupdatecli:mainfrom
railgun-0402:fix/7461-helmfile-invalid-ignore-spec

Conversation

@railgun-0402
Copy link
Contributor

@railgun-0402 railgun-0402 commented Jan 28, 2026

Fix #7461

Summary

This PR makes Helmfile autodiscovery fail fast on invalid spec.ignore rules instead of silently discovering 0 items.

  • Treat empty matching rules (no path, repositories, or charts) as invalid.
  • Return a clear error for invalid ignore specs so the CLI exits non-zero.
  • Add tests to prevent regressions.

Test

Additional Information

Checklist

  • I have updated the documentation via pull request in the website repository (if applicable).

Tradeoff

  • This introduces stricter validation: previously invalid ignore specs could be accepted and result in 0 discoveries.
    Now they are rejected with an error to avoid silent failures.

Potential improvement

  • If maintainers want a more user-friendly UX, we could expand the error message to include examples of the supported spec.ignore structure.

@olblak
Copy link
Member

olblak commented Jan 28, 2026

Thank you very much, it's a nice catch which I think we should also fix on the other autodiscovery plugins as they have similar implementation

@olblak olblak merged commit 63ee74d into updatecli:main Jan 28, 2026
9 checks passed
@olblak olblak added bug Something isn't working helmfile autodiscovery All things related to the autodiscovery feature labels Jan 28, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #7461 by making Helmfile autodiscovery fail fast with clear errors when given invalid spec.ignore or spec.only rules, instead of silently discovering 0 items.

Changes:

  • Added validation to reject empty matching rules (rules with no path, repositories, or charts fields)
  • Enabled strict mapstructure decoding with ErrorUnused: true to catch invalid spec structures
  • Changed autodiscovery error logging from Info to Errorln and made the function return an error on validation failures

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/plugins/autodiscovery/helmfile/matchingRule.go Adds Validate() method to check that each matching rule has at least one non-empty field
pkg/plugins/autodiscovery/helmfile/matchingRule_test.go Comprehensive unit tests for the new validation logic
pkg/plugins/autodiscovery/helmfile/main.go Integrates validation in the New() function and enables strict mapstructure decoding
pkg/plugins/autodiscovery/helmfile/main_test.go Integration tests verifying that invalid ignore/only specs are properly rejected
pkg/core/pipeline/autodiscovery/main.go Changes error handling to log errors properly and return non-zero exit code when autodiscovery fails

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +72
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
ErrorUnused: true,
Result: &s,
})
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The addition of ErrorUnused: true is a breaking change that will reject configurations with unused fields. While this helps catch the issue described in #7461 where users provide incorrectly structured YAML, it could also break existing configurations that have typos or extra fields that were previously silently ignored.

Consider whether this strictness aligns with the project's compatibility policy. An alternative would be to log a warning for unused fields instead of erroring, though this wouldn't solve the original issue of catching the invalid structure.

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +202
func TestNewWithInvalidIgnoreSpec(t *testing.T) {
tests := []struct {
name string
spec Spec
rootDir string
expectError bool
errorMsg string
}{
{
name: "valid ignore spec should pass",
spec: Spec{
Ignore: MatchingRules{
{Repositories: []string{"https://helm.example.com"}},
},
},
rootDir: "testdata",
expectError: false,
},
{
name: "empty ignore rule should fail",
spec: Spec{
Ignore: MatchingRules{
{},
},
},
rootDir: "testdata",
expectError: true,
errorMsg: "invalid ignore spec",
},
{
name: "valid only spec should pass",
spec: Spec{
Only: MatchingRules{
{Path: "testdata/*.yaml"},
},
},
rootDir: "testdata",
expectError: false,
},
{
name: "empty only rule should fail",
spec: Spec{
Only: MatchingRules{
{},
},
},
rootDir: "testdata",
expectError: true,
errorMsg: "invalid only spec",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := New(tt.spec, tt.rootDir, "", "")
if tt.expectError {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.errorMsg)
} else {
require.NoError(t, err)
}
})
}
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The test cases only verify that empty MatchingRule objects are caught by validation, but they don't test the actual issue case from #7461 where a user provides incorrectly structured input like ignore: { repositories: [...] } instead of ignore: [{ repositories: [...] }]. Consider adding a test that passes raw map input (similar to what would come from YAML parsing) to verify that both the decoder and validation work together to catch the reported issue.

Copilot uses AI. Check for mistakes.
@olblak olblak mentioned this pull request Jan 30, 2026
3 tasks
@olblak olblak changed the title helmfile autodiscovery: error on invalid ignore spec fix(autodiscovery/helmfile): error on invalid ignore spec Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autodiscovery All things related to the autodiscovery feature bug Something isn't working helmfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helmfile autodiscovery silently fails when given invalid ignore spec

2 participants