Skip to content

fix: rewrite relative file:// chart dependencies to absolute paths - #2334

Merged
yxxhero merged 1 commit into
helmfile:mainfrom
sstarcher:feature/kust_dep
Dec 20, 2025
Merged

yxxhero merged 1 commit into
helmfile:mainfrom
sstarcher:feature/kust_dep

Conversation

@sstarcher

Copy link
Copy Markdown
Contributor

Fixes an issue where Chart.yaml dependencies with relative file:// paths fail during chartification because the paths become invalid when the chart is copied to chartify's temporary directory.

The rewriteChartDependencies function now converts relative file:// dependencies to absolute paths before chartification, then restores the original Chart.yaml afterwards. Absolute file:// and other repository types (https, oci) are left unchanged.

Includes comprehensive test coverage for various dependency scenarios.

@yxxhero

yxxhero commented Dec 17, 2025

Copy link
Copy Markdown
Member

@sstarcher please fix lint issue.

@sstarcher
sstarcher force-pushed the feature/kust_dep branch 2 times, most recently from b93cffa to bd08358 Compare December 17, 2025 18:23
@yxxhero
yxxhero requested a review from Copilot December 18, 2025 13:35

Copilot AI left a comment

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.

Pull request overview

This PR fixes an issue where Chart.yaml dependencies with relative file:// paths fail during chartification. When charts are copied to chartify's temporary directory, relative paths become invalid. The solution adds a rewriteChartDependencies function that converts relative file:// dependencies to absolute paths before chartification, then restores the original Chart.yaml afterward using a cleanup function.

Key changes:

  • Adds rewriteChartDependencies method to HelmState that rewrites relative file:// paths to absolute paths
  • Integrates this rewriting into processChartification before chartify processes the chart
  • Provides comprehensive test coverage with multiple scenarios including edge cases

Reviewed changes

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

File Description
pkg/state/state.go Implements rewriteChartDependencies function to convert relative file:// dependency paths to absolute paths, and integrates it into the chartification process with cleanup restoration
pkg/state/chart_dependencies_rewrite_test.go Adds comprehensive test coverage for the dependency rewriting functionality, including tests for various dependency types, error handling, field preservation, and cleanup restoration

Comment thread pkg/state/state.go Resolved
Comment thread pkg/state/state.go
Comment on lines +1379 to +1381
Name string `yaml:"name"`
Repository string `yaml:"repository"`
Version string `yaml:"version"`

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

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

The ChartDependency struct only includes name, repository, and version fields. Helm Chart.yaml dependencies can also include additional fields like 'condition', 'tags', 'import-values', 'alias', and 'enabled'. When the Chart.yaml is unmarshaled and then marshaled back, these fields will be lost. Consider adding these fields to the ChartDependency struct with appropriate yaml tags and omitempty options to preserve the complete dependency information.

Suggested change
Name string `yaml:"name"`
Repository string `yaml:"repository"`
Version string `yaml:"version"`
Name string `yaml:"name"`
Repository string `yaml:"repository"`
Version string `yaml:"version"`
Condition string `yaml:"condition,omitempty"`
Tags []string `yaml:"tags,omitempty"`
ImportValues []interface{} `yaml:"import-values,omitempty"`
Alias string `yaml:"alias,omitempty"`
Enabled bool `yaml:"enabled,omitempty"`

Copilot uses AI. Check for mistakes.
Comment on lines +486 to +501
// Helper function to check if a string contains a substring
func containsString(s, substr string) bool {
return len(s) >= len(substr) && findSubstring(s, substr)
}

func findSubstring(s, substr string) bool {
if len(s) < len(substr) {
return false
}
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

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

The custom containsString and findSubstring helper functions reinvent functionality that is already available in the standard library. Use strings.Contains from the "strings" package instead, which is more idiomatic, well-tested, and readable.

Copilot uses AI. Check for mistakes.
Comment thread pkg/state/state.go Resolved
Comment thread pkg/state/state.go Resolved
Fixes an issue where Chart.yaml dependencies with relative file:// paths
fail during chartification because the paths become invalid when the chart
is copied to chartify's temporary directory.

The rewriteChartDependencies function now converts relative file://
dependencies to absolute paths before chartification, then restores the
original Chart.yaml afterwards. Absolute file:// and other repository
types (https, oci) are left unchanged.

Includes comprehensive test coverage for various dependency scenarios.

Signed-off-by: Shane Starcher <[email protected]>
@yxxhero
yxxhero merged commit 61f4a31 into helmfile:main Dec 20, 2025
@sstarcher
sstarcher deleted the feature/kust_dep branch December 22, 2025 13:12
yxxhero added a commit that referenced this pull request Jun 29, 2026
…deps (#2673)

* test: add integration test for issue #1880 transformers with file:// deps

Add an integration test reproducing the exact scenario from issue #1880:
a local chart with a relative file:// dependency (file://../library) used
together with kustomize transformers.

Before the fix (rewriteChartDependencies in PR #2334), chartify copied
the chart to a temp directory, breaking the relative file:// path and
causing helm dependency up to fail with:
  Error: directory /tmp/chartify.../monitoring/library not found

Also fix test artifact leak in issue923_test.go where OCI chart downloads
wrote to CWD because OutputDirTemplate lacked {{ .OutputDir }}.

Closes #1880

Signed-off-by: yxxhero <[email protected]>

* fix(test): guard exit-code captures against set -e in integration tests

Under set -e (enabled in run.sh), a failing command exits the shell
before 'var=$?' can execute, defeating diagnostic cat+fail blocks and
breaking helm diff tests that expect exit code 2.

Replaced 'cmd; var=$?' with 'var=0; cmd || var=$?' across 12 test
files (29 sites), matching the pattern already used in oci-parallel-pull.sh.

Signed-off-by: yxxhero <[email protected]>

---------

Signed-off-by: yxxhero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants