diff --git a/core/src/plugins/kubernetes/helm/handlers.ts b/core/src/plugins/kubernetes/helm/handlers.ts index 37ea1f4865..ef21746256 100644 --- a/core/src/plugins/kubernetes/helm/handlers.ts +++ b/core/src/plugins/kubernetes/helm/handlers.ts @@ -31,28 +31,28 @@ export const helmModuleHandlers: Partial> = { baseFields, tasks, tests, - dummyBuild, + dummyBuild: d, convertBuildDependency, prepareRuntimeDependencies, } = params + let dummyBuild = d const actions: (ExecBuildConfig | HelmActionConfig)[] = [] - - if (dummyBuild) { - actions.push(dummyBuild) - } else { - // We make a dummy build without a `copyFrom` or any build dependencies. This is to ensure there's a build action - // for this module if it's used as a base by another Helm module. - actions.push(makeDummyBuild({ module, copyFrom: undefined, dependencies: undefined })) + if (!dummyBuild) { + // We create a dummy build without a `copyFrom` or any build dependencies, to ensure there's a build action + // for this module. This is needed for compatibility reasions e.g. if there was a `base` field on the module + // or if a helm chart references dependent local charts relative to the modules build directory. + // We set the deploy actions `build` param to the dummy build to use the `buildPath` for all helm operations. + dummyBuild = makeDummyBuild({ + module, + copyFrom: undefined, + dependencies: undefined, + }) } + actions.push(dummyBuild) // There's one service on helm modules expect when skipDeploy = true const service: (typeof services)[0] | undefined = services[0] - // The helm Deploy type does not support the `base` field. We handle the field here during conversion, - // for compatibility. - // Note: A dummyBuild will be set if `base` is set on the Module, because the module configure handler then - // sets a `build.dependencies[].copy` directive. - let deployAction: HelmDeployConfig | null = null // If this Helm module has `skipDeploy = true`, there won't be a service config for us to convert here. diff --git a/core/src/plugins/kubernetes/helm/module-config.ts b/core/src/plugins/kubernetes/helm/module-config.ts index 327e9a9189..c942d988fe 100644 --- a/core/src/plugins/kubernetes/helm/module-config.ts +++ b/core/src/plugins/kubernetes/helm/module-config.ts @@ -210,7 +210,7 @@ export async function configureHelmModule({ ] } - const yamlPath = join(module.path, chartPath, helmChartYamlFilename) + const yamlPath = join(moduleConfig.path, chartPath, helmChartYamlFilename) const containsSources = await pathExists(yamlPath) if (base) { diff --git a/core/test/data/test-projects/helm/chart-with-dependency/.helmignore b/core/test/data/test-projects/helm/chart-with-dependency-action/.helmignore similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/.helmignore rename to core/test/data/test-projects/helm/chart-with-dependency-action/.helmignore diff --git a/core/test/data/test-projects/helm/chart-with-dependency/Chart.yaml b/core/test/data/test-projects/helm/chart-with-dependency-action/Chart.yaml similarity index 80% rename from core/test/data/test-projects/helm/chart-with-dependency/Chart.yaml rename to core/test/data/test-projects/helm/chart-with-dependency-action/Chart.yaml index 238013e9dd..a7a6d04d3d 100644 --- a/core/test/data/test-projects/helm/chart-with-dependency/Chart.yaml +++ b/core/test/data/test-projects/helm/chart-with-dependency-action/Chart.yaml @@ -11,3 +11,6 @@ dependencies: - name: postgresql version: "11.6.12" repository: https://charts.bitnami.com/bitnami + - name: frontend + version: 0.1.x + repository: file://../frontend diff --git a/core/test/data/test-projects/helm/chart-with-dependency-action/garden.yml b/core/test/data/test-projects/helm/chart-with-dependency-action/garden.yml new file mode 100644 index 0000000000..abafe095fe --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-action/garden.yml @@ -0,0 +1,10 @@ +kind: Deploy +description: The API backend for the voting UI +type: helm +name: chart-with-dependency-action +spec: + values: + image: + tag: ${modules.api-image.version} + ingress: + enabled: false diff --git a/core/test/data/test-projects/helm/chart-with-dependency-action/requirements.lock b/core/test/data/test-projects/helm/chart-with-dependency-action/requirements.lock new file mode 100644 index 0000000000..9e84c2561a --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-action/requirements.lock @@ -0,0 +1,9 @@ +dependencies: +- name: postgresql + repository: https://charts.bitnami.com/bitnami + version: 11.6.12 +- name: frontend + repository: file://../frontend + version: 0.1.0 +digest: sha256:5dddf147b1f1210219f174a5f04547588622e606ff7d8ab890ff0e88fa85dbcd +generated: "2023-10-04T18:21:23.739632+02:00" diff --git a/core/test/data/test-projects/helm/chart-with-dependency/templates/NOTES.txt b/core/test/data/test-projects/helm/chart-with-dependency-action/templates/NOTES.txt similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/templates/NOTES.txt rename to core/test/data/test-projects/helm/chart-with-dependency-action/templates/NOTES.txt diff --git a/core/test/data/test-projects/helm/chart-with-dependency/templates/_helpers.tpl b/core/test/data/test-projects/helm/chart-with-dependency-action/templates/_helpers.tpl similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/templates/_helpers.tpl rename to core/test/data/test-projects/helm/chart-with-dependency-action/templates/_helpers.tpl diff --git a/core/test/data/test-projects/helm/chart-with-dependency/templates/deployment.yaml b/core/test/data/test-projects/helm/chart-with-dependency-action/templates/deployment.yaml similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/templates/deployment.yaml rename to core/test/data/test-projects/helm/chart-with-dependency-action/templates/deployment.yaml diff --git a/core/test/data/test-projects/helm/chart-with-dependency/templates/service.yaml b/core/test/data/test-projects/helm/chart-with-dependency-action/templates/service.yaml similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/templates/service.yaml rename to core/test/data/test-projects/helm/chart-with-dependency-action/templates/service.yaml diff --git a/core/test/data/test-projects/helm/chart-with-dependency/values.yaml b/core/test/data/test-projects/helm/chart-with-dependency-action/values.yaml similarity index 100% rename from core/test/data/test-projects/helm/chart-with-dependency/values.yaml rename to core/test/data/test-projects/helm/chart-with-dependency-action/values.yaml diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/.helmignore b/core/test/data/test-projects/helm/chart-with-dependency-module/.helmignore new file mode 100644 index 0000000000..50af031725 --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/Chart.yaml b/core/test/data/test-projects/helm/chart-with-dependency-module/Chart.yaml new file mode 100644 index 0000000000..016690eb6a --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/Chart.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: chart-with-dependency +version: 0.1.0 +image: + repository: busybox + tag: latest + pullPolicy: IfNotPresent +dependencies: + - name: postgresql + version: "11.6.12" + repository: https://charts.bitnami.com/bitnami + - name: frontend + version: 0.1.x + repository: file://../../../frontend diff --git a/core/test/data/test-projects/helm/chart-with-dependency/garden.yml b/core/test/data/test-projects/helm/chart-with-dependency-module/garden.yml similarity index 86% rename from core/test/data/test-projects/helm/chart-with-dependency/garden.yml rename to core/test/data/test-projects/helm/chart-with-dependency-module/garden.yml index 01a20a2d57..645fae941a 100644 --- a/core/test/data/test-projects/helm/chart-with-dependency/garden.yml +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/garden.yml @@ -1,7 +1,7 @@ kind: Module description: The API backend for the voting UI type: helm -name: chart-with-dependency +name: chart-with-dependency-module serviceResource: kind: Deployment containerModule: api-image @@ -10,4 +10,3 @@ values: tag: ${modules.api-image.version} ingress: enabled: false - diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/templates/NOTES.txt b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/NOTES.txt new file mode 100644 index 0000000000..4eab4da896 --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range $.Values.ingress.paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "chart-with-namespace.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ include "chart-with-namespace.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "chart-with-namespace.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "chart-with-namespace.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/templates/_helpers.tpl b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/_helpers.tpl new file mode 100644 index 0000000000..1381901f29 --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "chart-with-namespace.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "chart-with-namespace.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "chart-with-namespace.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/templates/deployment.yaml b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/deployment.yaml new file mode 100644 index 0000000000..c394c35cc0 --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/deployment.yaml @@ -0,0 +1,49 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "chart-with-namespace.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "chart-with-namespace.name" . }} + helm.sh/chart: {{ include "chart-with-namespace.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "chart-with-namespace.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "chart-with-namespace.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: [python, app.py] + ports: + - name: http + containerPort: 80 + protocol: TCP + env: + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/templates/service.yaml b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/service.yaml new file mode 100644 index 0000000000..d77cd81690 --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "chart-with-namespace.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "chart-with-namespace.name" . }} + helm.sh/chart: {{ include "chart-with-namespace.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "chart-with-namespace.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/core/test/data/test-projects/helm/chart-with-dependency-module/values.yaml b/core/test/data/test-projects/helm/chart-with-dependency-module/values.yaml new file mode 100644 index 0000000000..200d11a04d --- /dev/null +++ b/core/test/data/test-projects/helm/chart-with-dependency-module/values.yaml @@ -0,0 +1,48 @@ +# Default values for chart-with-namespace. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: api-image + tag: stable + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + paths: [] + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/core/test/data/test-projects/helm/frontend/.helmignore b/core/test/data/test-projects/helm/frontend/.helmignore new file mode 100644 index 0000000000..50af031725 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/core/test/data/test-projects/helm/frontend/Chart.yaml b/core/test/data/test-projects/helm/frontend/Chart.yaml new file mode 100644 index 0000000000..9f9cc0aa03 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: frontend +version: 0.1.0 +image: + repository: busybox + tag: latest + pullPolicy: IfNotPresent diff --git a/core/test/data/test-projects/helm/frontend/templates/NOTES.txt b/core/test/data/test-projects/helm/frontend/templates/NOTES.txt new file mode 100644 index 0000000000..99b663b391 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range $.Values.ingress.paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "frontend.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ include "frontend.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "frontend.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "frontend.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/core/test/data/test-projects/helm/frontend/templates/_helpers.tpl b/core/test/data/test-projects/helm/frontend/templates/_helpers.tpl new file mode 100644 index 0000000000..99f6e20845 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "frontend.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "frontend.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "frontend.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/core/test/data/test-projects/helm/frontend/templates/deployment.yaml b/core/test/data/test-projects/helm/frontend/templates/deployment.yaml new file mode 100644 index 0000000000..22a6246871 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/templates/deployment.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "frontend.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + helm.sh/chart: {{ include "frontend.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + shareProcessNamespace: {{ .Values.shareProcessNamespace }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/core/test/data/test-projects/helm/frontend/templates/ingress.yaml b/core/test/data/test-projects/helm/frontend/templates/ingress.yaml new file mode 100644 index 0000000000..a6573efc65 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/templates/ingress.yaml @@ -0,0 +1,90 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "frontend.fullname" . -}} +{{- $ingressPaths := .Values.ingress.paths -}} + +{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" -}} + +# Use the new Ingress manifest structure +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + helm.sh/chart: {{ include "frontend.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + {{- range $ingressPaths }} + - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ $fullName }} + port: + number: 80 + {{- end }} + {{- end }} + +{{- else -}} + +# Use the old Ingress manifest structure +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + helm.sh/chart: {{ include "frontend.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + {{- range $ingressPaths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} + {{- end }} + + +{{- end }} +{{- end }} diff --git a/core/test/data/test-projects/helm/frontend/templates/service.yaml b/core/test/data/test-projects/helm/frontend/templates/service.yaml new file mode 100644 index 0000000000..c396536dd8 --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "frontend.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "frontend.name" . }} + helm.sh/chart: {{ include "frontend.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "frontend.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/core/test/data/test-projects/helm/frontend/values.yaml b/core/test/data/test-projects/helm/frontend/values.yaml new file mode 100644 index 0000000000..2c16cf23dc --- /dev/null +++ b/core/test/data/test-projects/helm/frontend/values.yaml @@ -0,0 +1,51 @@ +# Default values for frontend. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + tag: latest + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + paths: [] + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# This field is whitelisted in `runPodSpecWhitelist`, so it should be included when running tests/tasks +shareProcessNamespace: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/core/test/integ/src/plugins/kubernetes/helm/common.ts b/core/test/integ/src/plugins/kubernetes/helm/common.ts index ac02786400..98cf58acf8 100644 --- a/core/test/integ/src/plugins/kubernetes/helm/common.ts +++ b/core/test/integ/src/plugins/kubernetes/helm/common.ts @@ -668,9 +668,9 @@ ${expectedIngressOutput} expect(pathFiles).to.include("Chart.yaml") }) - it("updates dependencies for local charts", async () => { + it("updates dependencies for local charts in build dir for modules", async () => { const action = await garden.resolveAction({ - action: graph.getDeploy("chart-with-dependency"), + action: graph.getDeploy("chart-with-dependency-module"), log, graph, }) @@ -682,10 +682,51 @@ ${expectedIngressOutput} const helmDependencyUpdateLogLine = log.entries.find( ({ msg }) => - msg?.includes("helm") && msg?.includes("dependency update") && msg.includes("chart-with-dependency") + msg?.includes("helm") && msg?.includes("dependency update") && msg.includes("chart-with-dependency-module") ) expect(helmDependencyUpdateLogLine).to.exist }) + + it("updates dependencies for local charts in action dir for native actions", async () => { + const action = await garden.resolveAction({ + action: graph.getDeploy("chart-with-dependency-action"), + log, + graph, + }) + + const l = log as any + l.entries = [] + + await prepareTemplates({ ctx, log, action }) + + const helmDependencyUpdateLogLine = log.entries.find( + ({ msg }) => + msg?.includes("helm") && msg?.includes("dependency update") && msg.includes("chart-with-dependency-action") + ) + expect(helmDependencyUpdateLogLine).to.exist + }) + + it("uses build directory for deploy actions converted from Helm modules", async () => { + const action = await garden.resolveAction({ + action: graph.getDeploy("chart-with-dependency-module"), + log, + graph, + }) + const buildPath = action.getBuildAction()?.getBuildPath() + const chartPath = await getChartPath(action) + expect(chartPath).to.equal(buildPath) + }) + + it("uses action directory for native deploy actions", async () => { + const action = await garden.resolveAction({ + action: graph.getDeploy("chart-with-dependency-action"), + log, + graph, + }) + const buildPath = action.getBuildAction()?.getBuildPath() + const chartPath = await getChartPath(action) + expect(chartPath).to.not.equal(buildPath) + }) }) context("chart.url is set", () => { diff --git a/core/test/integ/src/plugins/kubernetes/helm/config.ts b/core/test/integ/src/plugins/kubernetes/helm/config.ts index c3b7c57541..5d3ed85e54 100644 --- a/core/test/integ/src/plugins/kubernetes/helm/config.ts +++ b/core/test/integ/src/plugins/kubernetes/helm/config.ts @@ -107,7 +107,7 @@ describe("configureHelmModule", () => { description: "The API backend for the voting UI", disabled: false, generateFiles: undefined, - include: ["*.yaml", "*.yml"], + include: ["*", "charts/**/*", "templates/**/*"], inputs: {}, exclude: undefined, name: "api-module",