Skip to content

Conversation

@josill
Copy link
Contributor

@josill josill commented Jan 29, 2026

Fix #6200

This PR fixes Flux autodiscovery to properly handle multi-document YAML files containing multiple HelmRelease resources. Previously, discoverHelmreleaseManifests() would only process the first document in a multi-document YAML file, causing subsequent HelmRelease resources to be ignored.

Changes

  1. Refactored discoverHelmreleaseManifests() (pkg/plugins/autodiscovery/flux/helmreleaseManifests.go):

    • Now reads file content once and splits it into documents using bytes.Split()
    • Processes each document separately using loadHelmReleaseFromBytes()
    • Generates a manifest for each HelmRelease found in the file
  2. Fixed duplicate file path issue in searchFluxFiles() (pkg/plugins/autodiscovery/flux/utils.go):

    • Added tracking to prevent adding the same file path multiple times when multiple HelmRelease documents exist in one file
    • Applied the same fix for OCI repository files
  3. Added comprehensive test case (pkg/plugins/autodiscovery/flux/testdata/helmrelease/multi-release/):

    • Created test data with multiple HelmRelease documents in a single file
    • Added test case "Scenario - helmrelease Multiple releases in same file" that verifies both HelmReleases generate separate manifests
    • Updated TestSearchFluxFiles to include the new test file

Test

To test this pull request, you can run the following commands:

cd pkg/plugins/autodiscovery/flux
go test -v

Or to run the specific multi-document test case:

cd pkg/plugins/autodiscovery/flux
go test -v -run "TestDiscoverManifests/Scenario_-_helmrelease_Multiple_releases_in_same_file"

Additional Information

Checklist

  • Code follows the project's coding standards
  • Tests have been added/updated and pass successfully
  • No linter errors introduced
  • I have updated the documentation via pull request in website repository.

Tradeoff

Potential improvement

  • Consider extracting the document splitting logic into a shared utility function since both searchFluxFiles() and discoverHelmreleaseManifests() now use the same pattern

@josill josill force-pushed the fix/flux-multi-document-support branch from df7c946 to 30e9565 Compare January 29, 2026 19:39
@josill josill force-pushed the fix/flux-multi-document-support branch from 30e9565 to a93a823 Compare January 29, 2026 19:44
@josill josill marked this pull request as ready for review January 29, 2026 19:49
@olblak olblak changed the title Fix/flux multi document support Flux Autodiscovery Doesn't discover some HelmRelease #6200 Jan 30, 2026
@olblak olblak added bug Something isn't working autodiscovery All things related to the autodiscovery feature flux labels Jan 30, 2026
@olblak olblak requested a review from Copilot January 30, 2026 15:06
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 fixes Flux autodiscovery to properly handle multi-document YAML files containing multiple HelmRelease resources. Previously, only the first HelmRelease in a multi-document file would be discovered, causing subsequent resources to be ignored.

Changes:

  • Refactored HelmRelease manifest discovery to process each document in multi-document YAML files separately
  • Added tracking flags to prevent duplicate file paths when multiple resources exist in one file
  • Added comprehensive test coverage for multi-document YAML files

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/plugins/autodiscovery/flux/helmreleaseManifests.go Refactored to read files once, split by YAML document separator, and process each HelmRelease document individually
pkg/plugins/autodiscovery/flux/helmrelease.go Removed unused loadHelmRelease() function that only handled single documents
pkg/plugins/autodiscovery/flux/utils.go Added tracking flags to prevent adding the same file path multiple times when multiple HelmRelease or OCIRepository documents exist in one file
pkg/plugins/autodiscovery/flux/testdata/helmrelease/multi-release/multi-helmrelease.yaml Test data with three documents: two HelmRelease resources and one HelmRepository
pkg/plugins/autodiscovery/flux/main_test.go Added test case validating that two separate manifests are generated for the multi-document file
pkg/plugins/autodiscovery/flux/utils_test.go Updated to include the new multi-release test file in expected results

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

name: 'deps(flux): bump Helmrelease "udash"'
kind: 'yaml'
spec:
file: 'multi-helmrelease.yaml'
Copy link
Member

Choose a reason for hiding this comment

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

The target is missing the parameter documentindex to define where document Updatecli should update

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 flux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flux Autodiscovery Doesn't discover some HelmRelease

2 participants