Skip to content

Commit 5db03be

Browse files
committed
helm/kustomize generator: make path handling more robust
1 parent cbc1ac2 commit 5db03be

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/manifests/helm.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ var _ Generator = &HelmGenerator{}
4646
// Create a new HelmGenerator.
4747
// Deprecation warning: the parameters name, client and discoveryClient are ignored (can be passed as empty resp. nil) and will be removed in a future release;
4848
// the according values will be retrieved from the context passed to Generate().
49+
// If fsys is nil, the local operating system filesystem will be used, and chartPath can be an absolute or relative path (in the latter case it will be considered
50+
// relative to the current working directory). If fsys is non-nil, then chartPath should be a relative path; if an absolute path is supplied, it will be turned
51+
// An empty chartPath will be treated like ".".
4952
func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.Client, discoveryClient discovery.DiscoveryInterface) (*HelmGenerator, error) {
5053
g := HelmGenerator{}
5154
g.data = make(map[string]any)
@@ -57,9 +60,12 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
5760
return nil, err
5861
}
5962
chartPath = absoluteChartPath[1:]
63+
} else if filepath.IsAbs(chartPath) {
64+
chartPath = chartPath[1:]
6065
}
66+
chartPath = filepath.Clean(chartPath)
6167

62-
chartRaw, err := fs.ReadFile(fsys, chartPath+"/Chart.yaml")
68+
chartRaw, err := fs.ReadFile(fsys, filepath.Clean(chartPath+"/Chart.yaml"))
6369
if err != nil {
6470
return nil, err
6571
}
@@ -75,7 +81,7 @@ func NewHelmGenerator(name string, fsys fs.FS, chartPath string, client client.C
7581
}
7682
g.data["Chart"] = chartData
7783

78-
valuesRaw, err := fs.ReadFile(fsys, chartPath+"/values.yaml")
84+
valuesRaw, err := fs.ReadFile(fsys, filepath.Clean(chartPath+"/values.yaml"))
7985
if err == nil {
8086
g.data["Values"] = &map[string]any{}
8187
if err := kyaml.Unmarshal(valuesRaw, g.data["Values"]); err != nil {

pkg/manifests/kustomize.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var _ Generator = &KustomizeGenerator{}
4343
// Create a new KustomizeGenerator.
4444
// Deprecation warning: the parameter client is ignored (can be passed as nil) and will be removed in a future release;
4545
// the according value will be retrieved from the context passed to Generate().
46+
// If fsys is nil, the local operating system filesystem will be used, and kustomizationPath can be an absolute or relative path (in the latter case it will be considered
47+
// relative to the current working directory). If fsys is non-nil, then kustomizationPath should be a relative path; if an absolute path is supplied, it will be turned
48+
// An empty kustomizationPath will be treated like ".".
4649
func NewKustomizeGenerator(fsys fs.FS, kustomizationPath string, templateSuffix string, client client.Client) (*KustomizeGenerator, error) {
4750
g := KustomizeGenerator{
4851
files: make(map[string][]byte),
@@ -56,7 +59,10 @@ func NewKustomizeGenerator(fsys fs.FS, kustomizationPath string, templateSuffix
5659
return nil, err
5760
}
5861
kustomizationPath = absoluteKustomizationPath[1:]
62+
} else if filepath.IsAbs(kustomizationPath) {
63+
kustomizationPath = kustomizationPath[1:]
5964
}
65+
kustomizationPath = filepath.Clean(kustomizationPath)
6066

6167
options := &krusty.Options{
6268
LoadRestrictions: kustypes.LoadRestrictionsNone,

0 commit comments

Comments
 (0)