diff --git a/garden-service/test/data/test-projects/conftest-kubernetes/helm/garden.yml b/garden-service/test/data/test-projects/conftest-kubernetes/helm/garden.yml index f5c528349a..ecab1874fe 100644 --- a/garden-service/test/data/test-projects/conftest-kubernetes/helm/garden.yml +++ b/garden-service/test/data/test-projects/conftest-kubernetes/helm/garden.yml @@ -2,5 +2,6 @@ kind: Module description: Test Helm chart type: helm name: helm -chart: stable/postgresql -version: 8.6.4 +chart: postgresql +repo: https://charts.bitnami.com/bitnami +version: "8.10.5" diff --git a/garden-service/test/data/test-projects/helm/postgres/garden.yml b/garden-service/test/data/test-projects/helm/postgres/garden.yml index 87856e629f..7ccc92a96c 100644 --- a/garden-service/test/data/test-projects/helm/postgres/garden.yml +++ b/garden-service/test/data/test-projects/helm/postgres/garden.yml @@ -2,8 +2,9 @@ kind: Module description: Postgres database for storing voting results type: helm name: postgres -chart: stable/postgresql -version: 3.9.2 +chart: postgresql +repo: https://charts.bitnami.com/bitnami +version: "8.10.5" serviceResource: kind: StatefulSet name: postgres diff --git a/garden-service/test/integ/src/plugins/kubernetes/helm/common.ts b/garden-service/test/integ/src/plugins/kubernetes/helm/common.ts index 2e804ac024..2e4a39b732 100644 --- a/garden-service/test/integ/src/plugins/kubernetes/helm/common.ts +++ b/garden-service/test/integ/src/plugins/kubernetes/helm/common.ts @@ -9,7 +9,7 @@ import { TestGarden, makeTestGarden, dataDir, expectError } from "../../../../../helpers" import { resolve } from "path" import { expect } from "chai" -import { first } from "lodash" +import { first, uniq } from "lodash" import { containsSource, @@ -27,6 +27,7 @@ import { BuildTask } from "../../../../../../src/tasks/build" import { deline, dedent } from "../../../../../../src/util/string" import { ConfigGraph } from "../../../../../../src/config-graph" import { KubernetesPluginContext } from "../../../../../../src/plugins/kubernetes/config" +import { safeLoadAll } from "js-yaml" let helmTestGarden: TestGarden @@ -100,6 +101,7 @@ describe("Helm common functions", () => { it("should render and return the manifests for a local template", async () => { const module = graph.getModule("api") const templates = await renderTemplates(ctx, module, false, log) + expect(templates).to.eql(dedent` --- # Source: api/templates/service.yaml @@ -182,173 +184,14 @@ describe("Helm common functions", () => { it("should render and return the manifests for a remote template", async () => { const module = graph.getModule("postgres") const templates = await renderTemplates(ctx, module, false, log) - expect(templates).to.eql(dedent` - --- - # Source: postgresql/templates/secrets.yaml - apiVersion: v1 - kind: Secret - metadata: - name: postgres - labels: - app: postgresql - chart: postgresql-3.9.2 - release: "postgres" - heritage: "Helm" - type: Opaque - data: - postgresql-password: "cG9zdGdyZXM=" - --- - # Source: postgresql/templates/svc-headless.yaml - apiVersion: v1 - kind: Service - metadata: - name: postgres-headless - labels: - app: postgresql - chart: postgresql-3.9.2 - release: "postgres" - heritage: "Helm" - spec: - type: ClusterIP - clusterIP: None - ports: - - name: postgresql - port: 5432 - targetPort: postgresql - selector: - app: postgresql - release: "postgres" - --- - # Source: postgresql/templates/svc.yaml - apiVersion: v1 - kind: Service - metadata: - name: postgres - labels: - app: postgresql - chart: postgresql-3.9.2 - release: "postgres" - heritage: "Helm" - spec: - type: ClusterIP - ports: - - name: postgresql - port: 5432 - targetPort: postgresql - selector: - app: postgresql - release: "postgres" - role: master - --- - # Source: postgresql/templates/statefulset.yaml - apiVersion: apps/v1beta2 - kind: StatefulSet - metadata: - name: postgres - labels: - app: postgresql - chart: postgresql-3.9.2 - release: "postgres" - heritage: "Helm" - spec: - serviceName: postgres-headless - replicas: 1 - updateStrategy: - type: RollingUpdate - selector: - matchLabels: - app: postgresql - release: "postgres" - role: master - template: - metadata: - name: postgres - labels: - app: postgresql - chart: postgresql-3.9.2 - release: "postgres" - heritage: "Helm" - role: master - spec: - securityContext: - fsGroup: 1001 - runAsUser: 1001 - initContainers: - - name: init-chmod-data - image: docker.io/bitnami/minideb:latest - imagePullPolicy: "Always" - resources: - requests: - cpu: 250m - memory: 256Mi - command: - - sh - - -c - - | - chown -R 1001:1001 /bitnami - if [ -d /bitnami/postgresql/data ]; then - chmod 0700 /bitnami/postgresql/data; - fi - securityContext: - runAsUser: 0 - volumeMounts: - - name: data - mountPath: /bitnami/postgresql - containers: - - name: postgres - image: docker.io/bitnami/postgresql:10.6.0 - imagePullPolicy: "Always" - resources: - requests: - cpu: 250m - memory: 256Mi - env: - - name: POSTGRESQL_USERNAME - value: "postgres" - - name: POSTGRESQL_PASSWORD - valueFrom: - secretKeyRef: - name: postgres - key: postgresql-password - ports: - - name: postgresql - containerPort: 5432 - livenessProbe: - exec: - command: - - sh - - -c - - exec pg_isready -U "postgres" -h localhost - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 6 - readinessProbe: - exec: - command: - - sh - - -c - - exec pg_isready -U "postgres" -h localhost - initialDelaySeconds: 5 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 6 - volumeMounts: - - name: data - mountPath: /bitnami/postgresql - volumes: - volumeClaimTemplates: - - metadata: - name: data - spec: - accessModes: - - "ReadWriteOnce" - resources: - requests: - storage: "8Gi"\n - `) + + // The exact output will vary by K8s versions so we just validate that we get valid YAML and + // the expected kinds. + const parsed = safeLoadAll(templates) + expect(parsed.length).to.equal(4) + + const kinds = uniq(parsed.map((p) => p.kind)).sort() + expect(kinds).to.eql(["Secret", "Service", "StatefulSet"]) }) }) @@ -475,234 +318,12 @@ describe("Helm common functions", () => { const module = graph.getModule("postgres") const resources = await getChartResources(ctx, module, false, log) - expect(resources).to.eql([ - { - apiVersion: "v1", - kind: "Secret", - metadata: { - name: "postgres", - labels: { - app: "postgresql", - chart: "postgresql-3.9.2", - release: "postgres", - heritage: "Helm", - }, - annotations: {}, - }, - type: "Opaque", - data: { - "postgresql-password": "cG9zdGdyZXM=", - }, - }, - { - apiVersion: "v1", - kind: "Service", - metadata: { - name: "postgres-headless", - labels: { - app: "postgresql", - chart: "postgresql-3.9.2", - release: "postgres", - heritage: "Helm", - }, - annotations: {}, - }, - spec: { - type: "ClusterIP", - clusterIP: "None", - ports: [ - { - name: "postgresql", - port: 5432, - targetPort: "postgresql", - }, - ], - selector: { - app: "postgresql", - release: "postgres", - }, - }, - }, - { - apiVersion: "v1", - kind: "Service", - metadata: { - name: "postgres", - labels: { - app: "postgresql", - chart: "postgresql-3.9.2", - release: "postgres", - heritage: "Helm", - }, - annotations: {}, - }, - spec: { - type: "ClusterIP", - ports: [ - { - name: "postgresql", - port: 5432, - targetPort: "postgresql", - }, - ], - selector: { - app: "postgresql", - release: "postgres", - role: "master", - }, - }, - }, - { - apiVersion: "apps/v1beta2", - kind: "StatefulSet", - metadata: { - name: "postgres", - labels: { - app: "postgresql", - chart: "postgresql-3.9.2", - release: "postgres", - heritage: "Helm", - }, - annotations: {}, - }, - spec: { - serviceName: "postgres-headless", - replicas: 1, - updateStrategy: { - type: "RollingUpdate", - }, - selector: { - matchLabels: { - app: "postgresql", - release: "postgres", - role: "master", - }, - }, - template: { - metadata: { - name: "postgres", - labels: { - app: "postgresql", - chart: "postgresql-3.9.2", - release: "postgres", - heritage: "Helm", - role: "master", - }, - }, - spec: { - securityContext: { - fsGroup: 1001, - runAsUser: 1001, - }, - initContainers: [ - { - name: "init-chmod-data", - image: "docker.io/bitnami/minideb:latest", - imagePullPolicy: "Always", - resources: { - requests: { - cpu: "250m", - memory: "256Mi", - }, - }, - command: [ - "sh", - "-c", - "chown -R 1001:1001 /bitnami\nif [ -d /bitnami/postgresql/data ]; then\n " + - "chmod 0700 /bitnami/postgresql/data;\nfi\n", - ], - securityContext: { - runAsUser: 0, - }, - volumeMounts: [ - { - name: "data", - mountPath: "/bitnami/postgresql", - }, - ], - }, - ], - containers: [ - { - name: "postgres", - image: "docker.io/bitnami/postgresql:10.6.0", - imagePullPolicy: "Always", - resources: { - requests: { - cpu: "250m", - memory: "256Mi", - }, - }, - env: [ - { - name: "POSTGRESQL_USERNAME", - value: "postgres", - }, - { - name: "POSTGRESQL_PASSWORD", - valueFrom: { - secretKeyRef: { - name: "postgres", - key: "postgresql-password", - }, - }, - }, - ], - ports: [ - { - name: "postgresql", - containerPort: 5432, - }, - ], - livenessProbe: { - exec: { - command: ["sh", "-c", 'exec pg_isready -U "postgres" -h localhost'], - }, - initialDelaySeconds: 30, - periodSeconds: 10, - timeoutSeconds: 5, - successThreshold: 1, - failureThreshold: 6, - }, - readinessProbe: { - exec: { - command: ["sh", "-c", 'exec pg_isready -U "postgres" -h localhost'], - }, - initialDelaySeconds: 5, - periodSeconds: 10, - timeoutSeconds: 5, - successThreshold: 1, - failureThreshold: 6, - }, - volumeMounts: [ - { - name: "data", - mountPath: "/bitnami/postgresql", - }, - ], - }, - ], - volumes: null, - }, - }, - volumeClaimTemplates: [ - { - metadata: { - name: "data", - }, - spec: { - accessModes: ["ReadWriteOnce"], - resources: { - requests: { - storage: "8Gi", - }, - }, - }, - }, - ], - }, - }, - ]) + // The exact output will vary by K8s versions so we just validate that we get valid YAML and + // the expected kinds. + expect(resources.length).to.equal(4) + + const kinds = uniq(resources.map((p) => p.kind)).sort() + expect(kinds).to.eql(["Secret", "Service", "StatefulSet"]) }) it("should handle duplicate keys in template", async () => {