From 6640f8799e38e9be297312b61acc5b26cbca2173 Mon Sep 17 00:00:00 2001 From: Ardika Bagus Date: Sat, 28 Oct 2023 11:47:16 +0700 Subject: [PATCH] test: add Kustomize test case for multiple helm charts with different version Signed-off-by: Ardika Bagus --- .../helmchartinflationgenerator_test.go | 117 ++++++++++++++++++ .../HelmChartInflationGenerator_test.go | 10 +- .../{foo-chart => test-chart}/Chart.yaml | 4 +- .../templates/configmap.yaml | 0 .../{foo-chart => test-chart}/values.yaml | 0 5 files changed, 124 insertions(+), 7 deletions(-) rename plugin/builtin/helmchartinflationgenerator/testdata/charts/{foo-chart => test-chart}/Chart.yaml (95%) rename plugin/builtin/helmchartinflationgenerator/testdata/charts/{foo-chart => test-chart}/templates/configmap.yaml (100%) rename plugin/builtin/helmchartinflationgenerator/testdata/charts/{foo-chart => test-chart}/values.yaml (100%) diff --git a/api/krusty/helmchartinflationgenerator_test.go b/api/krusty/helmchartinflationgenerator_test.go index e57d8b83c4..daffa16a0a 100644 --- a/api/krusty/helmchartinflationgenerator_test.go +++ b/api/krusty/helmchartinflationgenerator_test.go @@ -567,6 +567,123 @@ metadata: `) } +// Reference: https://github.com/kubernetes-sigs/kustomize/issues/5163 +func TestHelmChartInflationGeneratorForMultipleChartsDifferentVersion(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t) + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + + copyValuesFilesTestChartsIntoHarness(t, th) + + th.WriteK(th.GetRoot(), ` +namespace: default +helmCharts: + - name: test-chart + releaseName: test + version: 1.0.0 + skipTests: true + - name: minecraft + repo: https://itzg.github.io/minecraft-server-charts + version: 3.1.3 + releaseName: test-1 + - name: minecraft + repo: https://itzg.github.io/minecraft-server-charts + version: 3.1.4 + releaseName: test-2 +`) + + m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled()) + th.AssertActualEqualsExpected(m, ` +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + chart: test-1.0.0 + name: my-deploy + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: test + template: + spec: + containers: + - image: test-image:v1.0.0 + imagePullPolicy: Always +--- +apiVersion: v1 +data: + rcon-password: Q0hBTkdFTUUh +kind: Secret +metadata: + labels: + app: test-1-minecraft + chart: minecraft-3.1.3 + heritage: Helm + release: test-1 + name: test-1-minecraft + namespace: default +type: Opaque +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: test-1-minecraft + chart: minecraft-3.1.3 + heritage: Helm + release: test-1 + name: test-1-minecraft + namespace: default +spec: + ports: + - name: minecraft + port: 25565 + protocol: TCP + targetPort: minecraft + selector: + app: test-1-minecraft + type: ClusterIP +--- +apiVersion: v1 +data: + rcon-password: Q0hBTkdFTUUh +kind: Secret +metadata: + labels: + app: test-2-minecraft + chart: minecraft-3.1.4 + heritage: Helm + release: test-2 + name: test-2-minecraft + namespace: default +type: Opaque +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: test-2-minecraft + chart: minecraft-3.1.4 + heritage: Helm + release: test-2 + name: test-2-minecraft + namespace: default +spec: + ports: + - name: minecraft + port: 25565 + protocol: TCP + targetPort: minecraft + selector: + app: test-2-minecraft + type: ClusterIP +`) +} + func copyValuesFilesTestChartsIntoHarness(t *testing.T, th *kusttest_test.HarnessEnhanced) { t.Helper() diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go index 3ba3ad8a09..d75b44d1dc 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go @@ -786,10 +786,10 @@ func TestHelmChartInflationGeneratorUsingVersionWithoutRepo(t *testing.T) { apiVersion: builtin kind: HelmChartInflationGenerator metadata: - name: foo-chart -name: foo-chart + name: test-chart +name: test-chart version: 1.0.0 -releaseName: foo-chart +releaseName: test chartHome: ./charts `) @@ -797,11 +797,11 @@ chartHome: ./charts assert.NoError(t, err) assert.Equal(t, "bar", cm) - chartDir := filepath.Join(th.GetRoot(), "charts/foo-chart") + chartDir := filepath.Join(th.GetRoot(), "charts/test-chart") assert.True(t, th.GetFSys().Exists(chartDir)) chartYamlContent, err := th.GetFSys().ReadFile(filepath.Join(chartDir, "Chart.yaml")) assert.NoError(t, err) - assert.Contains(t, string(chartYamlContent), "name: foo-chart") + assert.Contains(t, string(chartYamlContent), "name: test-chart") assert.Contains(t, string(chartYamlContent), "version: 1.0.0") } diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/Chart.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml similarity index 95% rename from plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/Chart.yaml rename to plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml index 559af039b1..418a298771 100644 --- a/plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/Chart.yaml +++ b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 -name: foo-chart -description: A Helm chart for Kubernetes +name: test-chart +description: A simple test helm chart. # A chart can be either an 'application' or a 'library' chart. # diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/templates/configmap.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/templates/configmap.yaml similarity index 100% rename from plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/templates/configmap.yaml rename to plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/templates/configmap.yaml diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/values.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/values.yaml similarity index 100% rename from plugin/builtin/helmchartinflationgenerator/testdata/charts/foo-chart/values.yaml rename to plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/values.yaml