Skip to content

Commit 146d36b

Browse files
authored
fix: #8870 manifest kustomize paths using env var with absolute path (#8877)
1 parent f9bdcce commit 146d36b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pkg/skaffold/render/renderer/kustomize/kustomize.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,16 @@ func (k Kustomize) Render(ctx context.Context, out io.Writer, builds []graph.Art
6868
kCLI := kubectl.NewCLI(k.cfg, "")
6969
useKubectlKustomize := !generate.KustomizeBinaryCheck() && generate.KubectlVersionCheck(kCLI)
7070

71-
for _, kustomizePath := range sUtil.AbsolutePaths(k.cfg.GetWorkingDir(), k.rCfg.Kustomize.Paths) {
71+
var kustomizePaths []string
72+
for _, kustomizePath := range k.rCfg.Kustomize.Paths {
73+
kPath, err := sUtil.ExpandEnvTemplate(kustomizePath, nil)
74+
if err != nil {
75+
return manifest.ManifestListByConfig{}, fmt.Errorf("unable to parse path %q: %w", kustomizePath, err)
76+
}
77+
kustomizePaths = append(kustomizePaths, kPath)
78+
}
79+
80+
for _, kustomizePath := range sUtil.AbsolutePaths(k.cfg.GetWorkingDir(), kustomizePaths) {
7281
out, err := k.render(ctx, kustomizePath, useKubectlKustomize, kCLI)
7382
if err != nil {
7483
return manifest.ManifestListByConfig{}, err
@@ -106,11 +115,6 @@ func (k Kustomize) Render(ctx context.Context, out io.Writer, builds []graph.Art
106115

107116
func (k Kustomize) render(ctx context.Context, kustomizePath string, useKubectlKustomize bool, kCLI *kubectl.CLI) ([]byte, error) {
108117
var out []byte
109-
var err error
110-
kPath, err := sUtil.ExpandEnvTemplate(kustomizePath, nil)
111-
if err != nil {
112-
return out, fmt.Errorf("unable to parse path %q: %w", kustomizePath, err)
113-
}
114118

115119
if !k.transformer.IsEmpty() && !sUtil.IsURL(kustomizePath) {
116120
temp, err := os.MkdirTemp("", "*")
@@ -120,17 +124,17 @@ func (k Kustomize) render(ctx context.Context, kustomizePath string, useKubectlK
120124
fs := newTmpFS(temp)
121125
defer fs.Cleanup()
122126

123-
if err := k.mirror(kPath, fs); err == nil {
124-
kPath = filepath.Join(temp, kPath)
127+
if err := k.mirror(kustomizePath, fs); err == nil {
128+
kustomizePath = filepath.Join(temp, kustomizePath)
125129
} else {
126130
return out, err
127131
}
128132
}
129133

130134
if useKubectlKustomize {
131-
return kCLI.Kustomize(ctx, kustomizeBuildArgs(k.rCfg.Kustomize.BuildArgs, kPath))
135+
return kCLI.Kustomize(ctx, kustomizeBuildArgs(k.rCfg.Kustomize.BuildArgs, kustomizePath))
132136
} else {
133-
cmd := exec.CommandContext(ctx, "kustomize", append([]string{"build"}, kustomizeBuildArgs(k.rCfg.Kustomize.BuildArgs, kPath)...)...)
137+
cmd := exec.CommandContext(ctx, "kustomize", append([]string{"build"}, kustomizeBuildArgs(k.rCfg.Kustomize.BuildArgs, kustomizePath)...)...)
134138
return sUtil.RunCmdOut(ctx, cmd)
135139
}
136140
}

0 commit comments

Comments
 (0)