1
0
mirror of synced 2026-03-01 11:16:56 +00:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Matheus Pimenta
5da7610020 Merge pull request #5678 from fluxcd/backport-5674-to-release/v2.7.x
[release/v2.7.x] fix: normalize path for Windows compatibility
2026-01-13 16:44:00 +00:00
Sibasis Padhi
4103640628 fix: normalize paths to prevent concatenation on Windows
Fixes #5673

On Windows, when using absolute paths like C:\path\to\dir,
the path could be incorrectly concatenated, resulting in:
C:\working\dir\C:\path\to\dir\file

This fix applies filepath.Abs() and filepath.Clean() to normalize
the path before using it, ensuring absolute paths are handled
correctly on all platforms.

Changes:
- Apply filepath.Abs() to convert relative paths to absolute
- Apply filepath.Clean() to remove redundant separators and resolve ..
- Add tests for absolute paths, complex paths with .., and paths
  with redundant separators to verify normalization works correctly

The tests use actual 'flux build kustomization' commands with:
1. Absolute paths (prevents concatenation bugs)
2. Paths with parent directory (..) references
3. Paths with redundant separators (//)

All tests verify the command produces correct output, ensuring
the path normalization fix works as expected.

Signed-off-by: Sibasis Padhi <sibasis.padhi@gmail.com>
(cherry picked from commit 7dd9fde7ce)
2026-01-13 16:41:33 +00:00
Matheus Pimenta
1d871c84f7 Merge pull request #5657 from fluxcd/backport-5656-to-release/v2.7.x
[release/v2.7.x] fix: #5654 by checking if both --chart and --chart-ref are set
2025-12-10 21:34:02 +00:00
Jesper Axelsen
763e77c7c5 fix: #5654 by check if both --chart and --chart-ref are set
Signed-off-by: Jesper Axelsen <jesperbaxelsen@gmail.com>
(cherry picked from commit 3fb05a604f)
2025-12-10 21:33:24 +00:00
Matheus Pimenta
8454b02a32 Merge pull request #5649 from fluxcd/backport-5648-to-release/v2.7.x
[release/v2.7.x] Update toolkit components
2025-11-27 10:18:48 +00:00
fluxcdbot
931f101cb1 Update toolkit components
- helm-controller to v1.4.5
  https://github.com/fluxcd/helm-controller/blob/v1.4.5/CHANGELOG.md

Signed-off-by: GitHub <noreply@github.com>
(cherry picked from commit 1e7dd5dfd8)
2025-11-27 10:08:17 +00:00
8 changed files with 85 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"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)
}
// 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() {
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
}

View File

@@ -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)
})
}
}

View File

@@ -182,6 +182,10 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
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()
if err != nil {
return err

View File

@@ -42,6 +42,11 @@ func TestCreateHelmRelease(t *testing.T) {
args: "create helmrelease podinfo --export",
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",
args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export",

2
go.mod
View File

@@ -12,7 +12,7 @@ require (
github.com/distribution/distribution/v3 v3.0.0
github.com/fluxcd/cli-utils v0.36.0-flux.15
github.com/fluxcd/go-git-providers v0.25.0
github.com/fluxcd/helm-controller/api v1.4.4
github.com/fluxcd/helm-controller/api v1.4.5
github.com/fluxcd/image-automation-controller/api v1.0.4
github.com/fluxcd/image-reflector-controller/api v1.0.4
github.com/fluxcd/kustomize-controller/api v1.7.3

4
go.sum
View File

@@ -174,8 +174,8 @@ github.com/fluxcd/gitkit v0.6.0 h1:iNg5LTx6ePo+Pl0ZwqHTAkhbUHxGVSY3YCxCdw7VIFg=
github.com/fluxcd/gitkit v0.6.0/go.mod h1:svOHuKi0fO9HoawdK4HfHAJJseZDHHjk7I3ihnCIqNo=
github.com/fluxcd/go-git-providers v0.25.0 h1:zkVgujjo2VjKXbucrlTyNhHd9x+27oqyghJX9uLwQv4=
github.com/fluxcd/go-git-providers v0.25.0/go.mod h1:8Mx5WRYb61FIjOA26DAi4Ls2rZUHSxP8Nl9qkQHDch8=
github.com/fluxcd/helm-controller/api v1.4.4 h1:3IFAvJxOBaF2xXItUynqlbgw/2YzTjkL/iBiubxqcHk=
github.com/fluxcd/helm-controller/api v1.4.4/go.mod h1:rCgx3qhjjtoIH+1EbzFC2vN71/pp0PgMDrZnGCZX5XY=
github.com/fluxcd/helm-controller/api v1.4.5 h1:hMEBtgXUbJjp+ah0jPI3OOQNVngoToOQvTgFgVpAjNg=
github.com/fluxcd/helm-controller/api v1.4.5/go.mod h1:rCgx3qhjjtoIH+1EbzFC2vN71/pp0PgMDrZnGCZX5XY=
github.com/fluxcd/image-automation-controller/api v1.0.4 h1:Fgdy97hXkyh/JFjxLIyq4ZDHsKsa49aumtrvIyjVd08=
github.com/fluxcd/image-automation-controller/api v1.0.4/go.mod h1:LLBf4XQJAgnpIMlZUwfpVIkCdUtBOi31B6fDbPwBCq4=
github.com/fluxcd/image-reflector-controller/api v1.0.4 h1:/JGpTZf4eMcKG2FpWfP5H7SneSrD5P8EvwGnHiH/WLY=

View File

@@ -1,8 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.4/helm-controller.crds.yaml
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.4/helm-controller.deployment.yaml
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.5/helm-controller.crds.yaml
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.5/helm-controller.deployment.yaml
- account.yaml
transformers:
- labels.yaml

View File

@@ -3,7 +3,7 @@ kind: Kustomization
resources:
- https://github.com/fluxcd/source-controller/releases/download/v1.7.4/source-controller.crds.yaml
- https://github.com/fluxcd/kustomize-controller/releases/download/v1.7.3/kustomize-controller.crds.yaml
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.4/helm-controller.crds.yaml
- https://github.com/fluxcd/helm-controller/releases/download/v1.4.5/helm-controller.crds.yaml
- https://github.com/fluxcd/notification-controller/releases/download/v1.7.5/notification-controller.crds.yaml
- https://github.com/fluxcd/image-reflector-controller/releases/download/v1.0.4/image-reflector-controller.crds.yaml
- https://github.com/fluxcd/image-automation-controller/releases/download/v1.0.4/image-automation-controller.crds.yaml