Skip to content

Conversation

@Bishibop
Copy link
Contributor

@Bishibop Bishibop commented Oct 27, 2025

Issue

Autodiscovery crashes when projects contain both HelmChart manifests and Support Bundle specs (or other mixed resource types) in the same directory.

Error:

file ./manifests/helmchart.yaml does not contain kind: SupportBundle

Root Cause

Autodiscovery was storing explicit file paths (e.g., ./manifests/helmchart.yaml) instead of glob patterns (e.g., ./**). This caused the extraction layer to use strict validation instead of lenient filtering, leading to failures when processing mixed resource types.

Solution

  • Changed autodiscovery to store glob patterns (./**) matching non-autodiscovery behavior
  • Both code paths now use the same extraction logic (eliminates duplication)
  • Added comprehensive test coverage (6 tests covering edge cases)

Fixes autodiscovery crash when projects contain both HelmChart manifests
and Support Bundle specs (or other mixed resource types).

## Problem

Autodiscovery was storing explicit file paths in the config instead of
glob patterns. This caused the extraction phase to use strict validation
(explicit path mode) instead of lenient filtering (glob pattern mode).

When mixed resource types existed (e.g., HelmChart + Support Bundle), the
strict validation would fail:
- DiscoverSupportBundlesFromManifests() processes all paths in config.Manifests
- It tries to validate helmchart.yaml as a SupportBundle
- Error: "file does not contain kind: SupportBundle"

## Root Cause

The extraction layer (`extractAllPathsAndMetadata`) was designed for glob
patterns, not explicit paths. Non-autodiscovery configs use patterns like
"./**/*.yaml" which trigger lenient filtering. Autodiscovery was storing
explicit paths like "./manifests/helmchart.yaml" which trigger strict
validation.

## Solution

Make autodiscovery store glob patterns (`./**`) instead of explicit file
paths. This:
- ✅ Eliminates code path duplication (both use same extraction logic)
- ✅ Fixes the bug (glob patterns use lenient filtering)
- ✅ Maintains discovery counts for user display
- ✅ Follows the design pattern of the system

Discovery still happens twice (once for counting/display, once for
extraction), but this is conceptually correct and has negligible
performance impact.

## Changes

- Autodiscovery block now stores patterns, not paths
- Added comprehensive test with all resource types (Chart, Preflight,
  Support Bundle, HelmChart manifest)
- Test reproduces the bug before the fix, passes after

## Testing

- Added TestLint_AutodiscoveryWithMixedManifests
- All existing lint tests still pass
- All pkg/lint2 tests still pass
Adds 5 additional tests to thoroughly cover autodiscovery scenarios.

## Phase 1: Critical Edge Cases
- TestLint_AutodiscoveryEmptyProject: Validates graceful handling of empty directories
- TestLint_AutodiscoveryChartWithoutHelmChart: Validates error when chart lacks HelmChart manifest
- TestLint_AutodiscoveryMultipleCharts: Tests scaling with multiple charts

## Phase 2: Robustness
- TestLint_AutodiscoveryHiddenDirectories: Confirms .git, .github, etc. are ignored
- TestLint_AutodiscoveryBothYamlExtensions: Tests both .yaml and .yml file discovery

All tests pass, bringing total autodiscovery test coverage to 6 tests:
1. Mixed manifests (bug reproduction + fix validation)
2. Empty project
3. Chart without HelmChart
4. Multiple charts
5. Hidden directories
6. Both YAML extensions

This provides comprehensive coverage of autodiscovery functionality.
Remove redundant 'Use recursive wildcard pattern' comments since the
parent comment (lines 177-178) already explains the glob pattern approach.

Add more meaningful comment explaining why Support Bundles and HelmChart
manifests are combined into config.Manifests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants