Compare commits
4 Commits
v2.7.5
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5da7610020 | ||
|
|
4103640628 | ||
|
|
1d871c84f7 | ||
|
|
763e77c7c5 |
@@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -97,6 +98,13 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) (err error) {
|
|||||||
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize the path to handle Windows absolute and relative paths correctly
|
||||||
|
buildKsArgs.path, err = filepath.Abs(buildKsArgs.path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to resolve absolute path: %w", err)
|
||||||
|
}
|
||||||
|
buildKsArgs.path = filepath.Clean(buildKsArgs.path)
|
||||||
|
|
||||||
if fs, err := os.Stat(buildKsArgs.path); err != nil || !fs.IsDir() {
|
if fs, err := os.Stat(buildKsArgs.path); err != nil || !fs.IsDir() {
|
||||||
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,3 +218,65 @@ spec:
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestBuildKustomizationPathNormalization verifies that absolute and complex
|
||||||
|
// paths are normalized to prevent path concatenation bugs (issue #5673).
|
||||||
|
// Without normalization, paths could be duplicated like: /path/test/path/test/file
|
||||||
|
func TestBuildKustomizationPathNormalization(t *testing.T) {
|
||||||
|
// Get absolute path to testdata to test absolute path handling
|
||||||
|
absTestDataPath, err := filepath.Abs("testdata/build-kustomization/podinfo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get absolute path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args string
|
||||||
|
resultFile string
|
||||||
|
assertFunc string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "build with absolute path",
|
||||||
|
args: "build kustomization podinfo --path " + absTestDataPath,
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build with complex relative path (parent dir)",
|
||||||
|
args: "build kustomization podinfo --path ./testdata/build-kustomization/../build-kustomization/podinfo",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "build with path containing redundant separators",
|
||||||
|
args: "build kustomization podinfo --path ./testdata//build-kustomization//podinfo",
|
||||||
|
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
|
||||||
|
assertFunc: "assertGoldenTemplateFile",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := map[string]string{
|
||||||
|
"fluxns": allocateNamespace("flux-system"),
|
||||||
|
}
|
||||||
|
setup(t, tmpl)
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var assert assertFunc
|
||||||
|
|
||||||
|
switch tt.assertFunc {
|
||||||
|
case "assertGoldenTemplateFile":
|
||||||
|
assert = assertGoldenTemplateFile(tt.resultFile, tmpl)
|
||||||
|
case "assertError":
|
||||||
|
assert = assertError(tt.resultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmdTestCase{
|
||||||
|
args: tt.args + " -n " + tmpl["fluxns"],
|
||||||
|
assert: assert,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.runTestCmd(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -182,6 +182,10 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("chart or chart-ref is required")
|
return fmt.Errorf("chart or chart-ref is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if helmReleaseArgs.chart != "" && helmReleaseArgs.chartRef != "" {
|
||||||
|
return fmt.Errorf("cannot use --chart in combination with --chart-ref")
|
||||||
|
}
|
||||||
|
|
||||||
sourceLabels, err := parseLabels()
|
sourceLabels, err := parseLabels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ func TestCreateHelmRelease(t *testing.T) {
|
|||||||
args: "create helmrelease podinfo --export",
|
args: "create helmrelease podinfo --export",
|
||||||
assert: assertError("chart or chart-ref is required"),
|
assert: assertError("chart or chart-ref is required"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "chart and chartRef used in combination",
|
||||||
|
args: "create helmrelease podinfo --chart podinfo --chart-ref foobar/podinfo --export",
|
||||||
|
assert: assertError("cannot use --chart in combination with --chart-ref"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "unknown source kind",
|
name: "unknown source kind",
|
||||||
args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export",
|
args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export",
|
||||||
|
|||||||
Reference in New Issue
Block a user