diff --git a/api/internal/builtins/HelmChartInflationGenerator.go b/api/internal/builtins/HelmChartInflationGenerator.go index e2a486e949..40437a2155 100644 --- a/api/internal/builtins/HelmChartInflationGenerator.go +++ b/api/internal/builtins/HelmChartInflationGenerator.go @@ -91,7 +91,7 @@ func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) { // be under the loader root (unless root restrictions are // disabled). if p.ValuesFile == "" { - p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml") + p.ValuesFile = filepath.Join(p.absChartHome(), p.Name, "values.yaml") } for i, file := range p.AdditionalValuesFiles { // use Load() to enforce root restrictions @@ -132,10 +132,17 @@ func (p *HelmChartInflationGeneratorPlugin) errIfIllegalValuesMerge() error { } func (p *HelmChartInflationGeneratorPlugin) absChartHome() string { + var chartHome string if filepath.IsAbs(p.ChartHome) { - return p.ChartHome + chartHome = p.ChartHome + } else { + chartHome = filepath.Join(p.h.Loader().Root(), p.ChartHome) + } + + if p.Version != "" && p.Repo != "" { + return filepath.Join(chartHome, fmt.Sprintf("%s-%s", p.Name, p.Version)) } - return filepath.Join(p.h.Loader().Root(), p.ChartHome) + return chartHome } func (p *HelmChartInflationGeneratorPlugin) runHelmCommand( 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/go.work.sum b/go.work.sum index bba8f3fada..1af0794195 100644 --- a/go.work.sum +++ b/go.work.sum @@ -72,7 +72,6 @@ github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCv github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/flowstack/go-jsonschema v0.1.1 h1:dCrjGJRXIlbDsLAgTJZTjhwUJnnxVWl1OgNyYh5nyDc= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I= @@ -149,8 +148,6 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5 h1:58+kh9C6jJVXYjt8IE48G2eWl6BjwU5Gj0gqY84fy78= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.27.3/go.mod h1:5vG284IBtfDAmDyrK+eGyZmUgUlmi+Wngqo557cZ6Gw= github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= @@ -211,51 +208,21 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7 golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -gomodules.xyz/jsonpatch/v2 v2.0.1 h1:xyiBuvkD2g5n7cYzx6u2sxQvsAy4QJsZFCzGVdzOXZ0= -gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485 h1:OB/uP/Puiu5vS5QMRPrXCDWUPb+kt8f1KW8oQzFejQw= -gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e h1:jRyg0XfpwWlhEV8mDfdNGBeSJM2fuyh9Yjrnd8kF2Ts= -google.golang.org/api v0.30.0 h1:yfrXXP61wVuLb0vBcG6qaOoIoqYEzOQS8jum51jkv2w= -google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 h1:Et6SkiuvnBn+SgrSYXs/BrUpGB4mbdwt4R3vaPIlicA= -google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= -gopkg.in/cheggaaa/pb.v1 v1.0.25 h1:Ev7yu1/f6+d+b3pi5vPdRPc6nNtP1umSfcWiEfRqv6I= -gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= -gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= -gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI= -gopkg.in/square/go-jose.v2 v2.2.2 h1:orlkJ3myw8CN1nVQHBFfloD+L3egixIa4FvUP6RosSA= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= -honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8= -k8s.io/apiserver v0.17.0 h1:XhUix+FKFDcBygWkQNp7wKKvZL030QUlH1o8vFeSgZA= -k8s.io/code-generator v0.17.0 h1:y+KWtDWNqlJzJu/kUy8goJZO0X71PGIpAHLX8a0JYk0= -k8s.io/component-base v0.17.0 h1:BnDFcmBDq+RPpxXjmuYnZXb59XNN9CaFrX8ba9+3xrA= -k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c h1:GohjlNKauSai7gN4wsJkeZ3WAJx4Sh+oT/b5IYn5suA= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= -modernc.org/cc v1.0.0 h1:nPibNuDEx6tvYrUAtvDTTw98rx5juGsa5zuDnKwEEQQ= -modernc.org/golex v1.0.0 h1:wWpDlbK8ejRfSyi0frMyhilD3JBvtcx2AdGDnU+JtsE= -modernc.org/mathutil v1.0.0 h1:93vKjrJopTPrtTNpZ8XIovER7iCIH1QU7wNbOQXC60I= -modernc.org/strutil v1.0.0 h1:XVFtQwFVwc02Wk+0L/Z/zDDXO81r5Lhe6iMKmGX3KhE= -modernc.org/xc v1.0.0 h1:7ccXrupWZIS3twbUGrtKmHS2DXY6xegFua+6O3xgAFU= -rsc.io/binaryregexp v0.2.0 h1:HfqmD5MEmC0zvwBuF187nq9mdnXjXsSivRiXN7SmRkE= -rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY= -rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06 h1:zD2IemQ4LmOcAumeiyDWXKUI2SO0NYDe3H6QGvPOVgU= diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index bca7fefade..01adb29f5b 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -97,7 +97,7 @@ func (p *plugin) validateArgs() (err error) { // be under the loader root (unless root restrictions are // disabled). if p.ValuesFile == "" { - p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml") + p.ValuesFile = filepath.Join(p.absChartHome(), p.Name, "values.yaml") } for i, file := range p.AdditionalValuesFiles { // use Load() to enforce root restrictions @@ -138,10 +138,17 @@ func (p *plugin) errIfIllegalValuesMerge() error { } func (p *plugin) absChartHome() string { + var chartHome string if filepath.IsAbs(p.ChartHome) { - return p.ChartHome + chartHome = p.ChartHome + } else { + chartHome = filepath.Join(p.h.Loader().Root(), p.ChartHome) + } + + if p.Version != "" && p.Repo != "" { + return filepath.Join(chartHome, fmt.Sprintf("%s-%s", p.Name, p.Version)) } - return filepath.Join(p.h.Loader().Root(), p.ChartHome) + return chartHome } func (p *plugin) runHelmCommand( diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go index 95ba98c618..d75b44d1dc 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator_test.go @@ -9,6 +9,7 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" "sigs.k8s.io/kustomize/kyaml/copyutil" @@ -626,3 +627,181 @@ func copyTestChartsIntoHarness(t *testing.T, th *kusttest_test.HarnessEnhanced) require.NoError(t, copyutil.CopyDir(th.GetFSys(), chartDir, thDir)) } + +func TestHelmChartInflationGeneratorWithSameChartMultipleVersions(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). + PrepBuiltin("HelmChartInflationGenerator") + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + tests := []struct { + name string + chartName string + repo string + version string + releaseName string + }{ + { + name: "terraform chart with no version grabs latest", + chartName: "terraform", + repo: "https://helm.releases.hashicorp.com", + version: "", + releaseName: "terraform-latest", + }, + { + name: "terraform chart with version 1.1.1", + chartName: "terraform", + repo: "https://helm.releases.hashicorp.com", + version: "1.1.1", + releaseName: "terraform-1.1.1", + }, + { + name: "terraform chart with version 1.1.1 again", + chartName: "terraform", + repo: "https://helm.releases.hashicorp.com", + version: "1.1.1", + releaseName: "terraform-1.1.1-1", + }, + { + name: "terraform chart with version 1.1.2", + chartName: "terraform", + repo: "https://helm.releases.hashicorp.com", + version: "1.1.2", + releaseName: "terraform-1.1.2", + }, + { + name: "terraform chart with version 1.1.2 but without repo", + chartName: "terraform", + version: "1.1.2", + releaseName: "terraform-1.1.2", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config := fmt.Sprintf(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: %s +name: %s +version: %s +repo: %s +releaseName: %s +`, tt.chartName, tt.chartName, tt.version, tt.repo, tt.releaseName) + + rm := th.LoadAndRunGenerator(config) + assert.True(t, len(rm.Resources()) > 0) + + var chartDir string + if tt.version != "" && tt.repo != "" { + chartDir = fmt.Sprintf("charts/%s-%s/%s", tt.chartName, tt.version, tt.chartName) + } else { + chartDir = fmt.Sprintf("charts/%s", tt.chartName) + } + + fmt.Printf("%s: %s\n", tt.name, chartDir) + + d, err := th.GetFSys().ReadFile(filepath.Join(th.GetRoot(), chartDir, "Chart.yaml")) + if err != nil { + t.Fatal(err) + } + + assert.Contains(t, string(d), fmt.Sprintf("name: %s", tt.chartName)) + if tt.version != "" { + assert.Contains(t, string(d), fmt.Sprintf("version: %s", tt.version)) + } + }) + } +} + +// Test that verifies +1 instances of same chart with different versions +// https://github.com/kubernetes-sigs/kustomize/issues/4813 +func TestHelmChartInflationGeneratorWithMultipleInstancesSameChartDifferentVersions(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). + PrepBuiltin("HelmChartInflationGenerator") + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + + podinfo1 := th.LoadAndRunGenerator(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: podinfo +name: podinfo +version: 6.2.1 +repo: https://stefanprodan.github.io/podinfo +releaseName: podinfo1 +`) + + podinfo2 := th.LoadAndRunGenerator(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: podinfo +name: podinfo +version: 6.1.8 +repo: https://stefanprodan.github.io/podinfo +releaseName: podinfo2 +`) + + podinfo1Img, err := podinfo1.Resources()[1].GetFieldValue("spec.template.spec.containers.0.image") + assert.NoError(t, err) + assert.Equal(t, "ghcr.io/stefanprodan/podinfo:6.2.1", podinfo1Img) + + podinfo2Img, err := podinfo2.Resources()[1].GetFieldValue("spec.template.spec.containers.0.image") + assert.NoError(t, err) + assert.Equal(t, "ghcr.io/stefanprodan/podinfo:6.1.8", podinfo2Img) + + podinfo1ChartsDir := filepath.Join(th.GetRoot(), "charts/podinfo-6.2.1/podinfo") + assert.True(t, th.GetFSys().Exists(podinfo1ChartsDir)) + + podinfo2ChartsDir := filepath.Join(th.GetRoot(), "charts/podinfo-6.1.8/podinfo") + assert.True(t, th.GetFSys().Exists(podinfo2ChartsDir)) + + podinfo1ChartContents, err := th.GetFSys().ReadFile(filepath.Join(podinfo1ChartsDir, "Chart.yaml")) + assert.NoError(t, err) + assert.Contains(t, string(podinfo1ChartContents), "version: 6.2.1") + + podinfo2ChartContents, err := th.GetFSys().ReadFile(filepath.Join(podinfo2ChartsDir, "Chart.yaml")) + assert.NoError(t, err) + assert.Contains(t, string(podinfo2ChartContents), "version: 6.1.8") +} + +// Reference: https://github.com/kubernetes-sigs/kustomize/issues/5163 +func TestHelmChartInflationGeneratorUsingVersionWithoutRepo(t *testing.T) { + th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t). + PrepBuiltin("HelmChartInflationGenerator") + defer th.Reset() + if err := th.ErrIfNoHelm(); err != nil { + t.Skip("skipping: " + err.Error()) + } + + copyTestChartsIntoHarness(t, th) + + rm := th.LoadAndRunGenerator(` +apiVersion: builtin +kind: HelmChartInflationGenerator +metadata: + name: test-chart +name: test-chart +version: 1.0.0 +releaseName: test +chartHome: ./charts +`) + + cm, err := rm.Resources()[0].GetFieldValue("metadata.name") + assert.NoError(t, err) + assert.Equal(t, "bar", cm) + + 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: test-chart") + assert.Contains(t, string(chartYamlContent), "version: 1.0.0") +} diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml new file mode 100644 index 0000000000..418a298771 --- /dev/null +++ b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: test-chart +description: A simple test helm chart. + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "stable" diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/templates/configmap.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/templates/configmap.yaml new file mode 100644 index 0000000000..b7c8ef451a --- /dev/null +++ b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/templates/configmap.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Values.foo }} diff --git a/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/values.yaml b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/values.yaml new file mode 100644 index 0000000000..20e9ff3fea --- /dev/null +++ b/plugin/builtin/helmchartinflationgenerator/testdata/charts/test-chart/values.yaml @@ -0,0 +1 @@ +foo: bar