Skip to content

Commit 6bb62dd

Browse files
authored
Merge pull request #5164 from kubernetes-sigs/revert-4999-fix-same-chart-multiple-versions
Revert "Fix using same helm chart with different versions"
2 parents c2bd42e + 3d6f40b commit 6bb62dd

File tree

3 files changed

+6
-167
lines changed

3 files changed

+6
-167
lines changed

api/internal/builtins/HelmChartInflationGenerator.go

Lines changed: 3 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ func (p *plugin) validateArgs() (err error) {
9797
// be under the loader root (unless root restrictions are
9898
// disabled).
9999
if p.ValuesFile == "" {
100-
// If the version is specified, use the versioned values file.
101-
if p.Version != "" {
102-
p.ValuesFile = filepath.Join(p.ChartHome, fmt.Sprintf("%s-%s", p.Name, p.Version), p.Name, "values.yaml")
103-
} else {
104-
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
105-
}
100+
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
106101
}
107102
for i, file := range p.AdditionalValuesFiles {
108103
// use Load() to enforce root restrictions
@@ -143,17 +138,10 @@ func (p *plugin) errIfIllegalValuesMerge() error {
143138
}
144139

145140
func (p *plugin) absChartHome() string {
146-
var chartHome string
147141
if filepath.IsAbs(p.ChartHome) {
148-
chartHome = p.ChartHome
149-
} else {
150-
chartHome = filepath.Join(p.h.Loader().Root(), p.ChartHome)
151-
}
152-
153-
if p.Version != "" {
154-
return filepath.Join(chartHome, fmt.Sprintf("%s-%s", p.Name, p.Version))
142+
return p.ChartHome
155143
}
156-
return chartHome
144+
return filepath.Join(p.h.Loader().Root(), p.ChartHome)
157145
}
158146

159147
func (p *plugin) runHelmCommand(

plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"testing"
1111

12-
"github.com/stretchr/testify/assert"
1312
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
1413
)
1514

@@ -580,139 +579,3 @@ valuesInline:
580579
`)
581580
th.AssertActualEqualsExpected(rm, "")
582581
}
583-
584-
func TestHelmChartInflationGeneratorWithSameChartMultipleVersions(t *testing.T) {
585-
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t).
586-
PrepBuiltin("HelmChartInflationGenerator")
587-
defer th.Reset()
588-
if err := th.ErrIfNoHelm(); err != nil {
589-
t.Skip("skipping: " + err.Error())
590-
}
591-
592-
tests := []struct {
593-
name string
594-
chartName string
595-
repo string
596-
version string
597-
releaseName string
598-
}{
599-
{
600-
name: "terraform chart with no version grabs latest",
601-
chartName: "terraform",
602-
repo: "https://helm.releases.hashicorp.com",
603-
version: "",
604-
releaseName: "terraform-latest",
605-
},
606-
{
607-
name: "terraform chart with version 1.1.1",
608-
chartName: "terraform",
609-
repo: "https://helm.releases.hashicorp.com",
610-
version: "1.1.1",
611-
releaseName: "terraform-1.1.1",
612-
},
613-
{
614-
name: "terraform chart with version 1.1.1 again",
615-
chartName: "terraform",
616-
repo: "https://helm.releases.hashicorp.com",
617-
version: "1.1.1",
618-
releaseName: "terraform-1.1.1-1",
619-
},
620-
{
621-
name: "terraform chart with version 1.1.2",
622-
chartName: "terraform",
623-
repo: "https://helm.releases.hashicorp.com",
624-
version: "1.1.2",
625-
releaseName: "terraform-1.1.2",
626-
},
627-
}
628-
629-
for _, tt := range tests {
630-
t.Run(tt.name, func(t *testing.T) {
631-
config := fmt.Sprintf(`
632-
apiVersion: builtin
633-
kind: HelmChartInflationGenerator
634-
metadata:
635-
name: %s
636-
name: %s
637-
version: %s
638-
repo: %s
639-
releaseName: %s
640-
`, tt.chartName, tt.chartName, tt.version, tt.repo, tt.releaseName)
641-
642-
rm := th.LoadAndRunGenerator(config)
643-
assert.True(t, len(rm.Resources()) > 0)
644-
645-
var chartDir string
646-
if tt.version != "" {
647-
chartDir = fmt.Sprintf("charts/%s-%s/%s", tt.chartName, tt.version, tt.chartName)
648-
} else {
649-
chartDir = fmt.Sprintf("charts/%s", tt.chartName)
650-
}
651-
652-
d, err := th.GetFSys().ReadFile(filepath.Join(th.GetRoot(), chartDir, "Chart.yaml"))
653-
if err != nil {
654-
t.Fatal(err)
655-
}
656-
657-
assert.Contains(t, string(d), fmt.Sprintf("name: %s", tt.chartName))
658-
if tt.version != "" {
659-
assert.Contains(t, string(d), fmt.Sprintf("version: %s", tt.version))
660-
}
661-
})
662-
}
663-
}
664-
665-
// Test that verifies +1 instances of same chart with different versions
666-
// https://github.com/kubernetes-sigs/kustomize/issues/4813
667-
func TestHelmChartInflationGeneratorWithMultipleInstancesSameChartDifferentVersions(t *testing.T) {
668-
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t).
669-
PrepBuiltin("HelmChartInflationGenerator")
670-
defer th.Reset()
671-
if err := th.ErrIfNoHelm(); err != nil {
672-
t.Skip("skipping: " + err.Error())
673-
}
674-
675-
podinfo1 := th.LoadAndRunGenerator(`
676-
apiVersion: builtin
677-
kind: HelmChartInflationGenerator
678-
metadata:
679-
name: podinfo
680-
name: podinfo
681-
version: 6.2.1
682-
repo: https://stefanprodan.github.io/podinfo
683-
releaseName: podinfo1
684-
`)
685-
686-
podinfo2 := th.LoadAndRunGenerator(`
687-
apiVersion: builtin
688-
kind: HelmChartInflationGenerator
689-
metadata:
690-
name: podinfo
691-
name: podinfo
692-
version: 6.1.8
693-
repo: https://stefanprodan.github.io/podinfo
694-
releaseName: podinfo2
695-
`)
696-
697-
podinfo1Img, err := podinfo1.Resources()[1].GetFieldValue("spec.template.spec.containers.0.image")
698-
assert.NoError(t, err)
699-
assert.Equal(t, "ghcr.io/stefanprodan/podinfo:6.2.1", podinfo1Img)
700-
701-
podinfo2Img, err := podinfo2.Resources()[1].GetFieldValue("spec.template.spec.containers.0.image")
702-
assert.NoError(t, err)
703-
assert.Equal(t, "ghcr.io/stefanprodan/podinfo:6.1.8", podinfo2Img)
704-
705-
podinfo1ChartsDir := filepath.Join(th.GetRoot(), "charts/podinfo-6.2.1/podinfo")
706-
assert.True(t, th.GetFSys().Exists(podinfo1ChartsDir))
707-
708-
podinfo2ChartsDir := filepath.Join(th.GetRoot(), "charts/podinfo-6.1.8/podinfo")
709-
assert.True(t, th.GetFSys().Exists(podinfo2ChartsDir))
710-
711-
podinfo1ChartContents, err := th.GetFSys().ReadFile(filepath.Join(podinfo1ChartsDir, "Chart.yaml"))
712-
assert.NoError(t, err)
713-
assert.Contains(t, string(podinfo1ChartContents), "version: 6.2.1")
714-
715-
podinfo2ChartContents, err := th.GetFSys().ReadFile(filepath.Join(podinfo2ChartsDir, "Chart.yaml"))
716-
assert.NoError(t, err)
717-
assert.Contains(t, string(podinfo2ChartContents), "version: 6.1.8")
718-
}

0 commit comments

Comments
 (0)