Repository navigation
fix: rewrite relative file:// chart dependencies to absolute paths - #2334
Conversation
|
@sstarcher please fix lint issue. |
b93cffa to
bd08358
Compare
There was a problem hiding this comment.
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
rewriteChartDependenciesmethod to HelmState that rewrites relative file:// paths to absolute paths - Integrates this rewriting into
processChartificationbefore 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 |
| Name string `yaml:"name"` | ||
| Repository string `yaml:"repository"` | ||
| Version string `yaml:"version"` |
There was a problem hiding this comment.
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.
| 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"` |
| // 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 | ||
| } |
There was a problem hiding this comment.
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.
5e81513 to
21686eb
Compare
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]>
d476e59 to
11265f4
Compare
…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]>
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.