diff --git a/pkg/controllers/chart/chart.go b/pkg/controllers/chart/chart.go index dda6e06f..a1039b00 100644 --- a/pkg/controllers/chart/chart.go +++ b/pkg/controllers/chart/chart.go @@ -476,6 +476,10 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret, Name: "klipper-config", MountPath: "/home/klipper-helm/.config", }, + { + Name: "tmp", + MountPath: "/tmp", + }, }, }, }, @@ -506,6 +510,14 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret, }, }, }, + { + Name: "tmp", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: "Memory", + }, + }, + }, }, }, }, diff --git a/test/framework/framework.go b/test/framework/framework.go index aaf7026d..b1756a3c 100644 --- a/test/framework/framework.go +++ b/test/framework/framework.go @@ -1,9 +1,12 @@ package framework import ( + "bytes" "context" + "encoding/base64" "fmt" "io" + "net/http" "os" "time" @@ -211,3 +214,25 @@ func (f *Framework) GetJob(chart *v1.HelmChart) (*batchv1.Job, error) { } return f.ClientSet.BatchV1().Jobs(chart.Namespace).Get(context.TODO(), chart.Status.JobName, metav1.GetOptions{}) } + +// GetChartContent returns the base64-encoded chart tarball, +// downloaded from the specified URL. +func (f *Framework) GetChartContent(url string) (string, error) { + resp, err := http.Get(url) + if err != nil { + return "", err + } + if resp.StatusCode != 200 { + return "", fmt.Errorf("unexpected HTTP response: %s", resp.Status) + } + + b := &bytes.Buffer{} + w := base64.NewEncoder(base64.StdEncoding, b) + if _, err := io.Copy(w, resp.Body); err != nil { + return "", err + } + if err := w.Close(); err != nil { + return "", err + } + return string(b.Bytes()), nil +} diff --git a/test/suite/helm_test.go b/test/suite/helm_test.go index 97576ec4..c128123a 100644 --- a/test/suite/helm_test.go +++ b/test/suite/helm_test.go @@ -244,6 +244,52 @@ var _ = Describe("Helm Tests", Ordered, func() { }) + Context("When a helm V3 chart specifies ChartContent", func() { + var ( + err error + chart *v1.HelmChart + pods []corev1.Pod + ) + BeforeEach(func() { + chart = framework.NewHelmChart("traefik-example-chartcontent", + "", + "1.86.1", + "v3", + "metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n", + map[string]intstr.IntOrString{ + "rbac.enabled": { + Type: intstr.String, + StrVal: "true", + }, + "ssl.enabled": { + Type: intstr.String, + StrVal: "true", + }, + }) + chart.Spec.ChartContent, err = framework.GetChartContent("https://charts.helm.sh/stable/packages/traefik-1.86.1.tgz") + Expect(err).ToNot(HaveOccurred()) + + chart, err = framework.CreateHelmChart(chart, framework.Namespace) + Expect(err).ToNot(HaveOccurred()) + + pods, err = framework.WaitForChartApp(chart, "traefik", 120*time.Second, 1) + Expect(err).ToNot(HaveOccurred()) + }) + It("Should install the release successfully", func() { + Expect(len(pods)).To(BeEquivalentTo(1)) + }) + AfterEach(func() { + err = framework.DeleteHelmChart(chart.Name, framework.Namespace) + Expect(err).ToNot(HaveOccurred()) + + Eventually(func() bool { + _, err := framework.GetHelmChart(chart.Name, framework.Namespace) + return err != nil && apierrors.IsNotFound(err) + }, 120*time.Second, 5*time.Second).Should(BeTrue()) + }) + + }) + Context("When a helm V3 chart creates a namespace", func() { var ( err error