diff --git a/examples/helm-deployment-dependencies/Dockerfile b/examples/helm-deployment-dependencies/Dockerfile new file mode 100644 index 00000000000..75eca2cb8ef --- /dev/null +++ b/examples/helm-deployment-dependencies/Dockerfile @@ -0,0 +1 @@ +FROM nginx:stable diff --git a/examples/helm-deployment-dependencies/README.adoc b/examples/helm-deployment-dependencies/README.adoc new file mode 100644 index 00000000000..9a1cff3e1a1 --- /dev/null +++ b/examples/helm-deployment-dependencies/README.adoc @@ -0,0 +1,25 @@ +=== Example: helm-dependencies +:icons: font + +==== Deploy helm charts with local dependencies + +This example follows the link:{github-repo-tree}/examples/helm-deployment-dependencies[helm] example, but with a local chart as a depenency. + +The `skipBuildDependencies` option is used to skip the `helm dep build` command. This must be disabled for charts with local dependencies. + +The image can be passed to the subchart using the standard Helm format of `subchart-name.value`. + +``` +deploy: + helm: + releases: + - name: skaffold-helm + chartPath: skaffold-helm + namespace: skaffold + skipBuildDependencies: true # Skip helm dep build + values: + image: skaffold-helm + "subchart.image": gcr.io/k8s-skaffold/skaffold-helm # Set image for subchart + valuesFiles: + - helm-values-file.yaml +``` diff --git a/examples/helm-deployment-dependencies/skaffold-helm/.helmignore b/examples/helm-deployment-dependencies/skaffold-helm/.helmignore new file mode 100644 index 00000000000..f0c13194444 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml b/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml new file mode 100644 index 00000000000..f4fcfadbec9 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: skaffold-helm +version: 0.1.0 diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore new file mode 100644 index 00000000000..f0c13194444 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml new file mode 100644 index 00000000000..3879caeaabd --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: subchart +version: 0.1.0 diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl new file mode 100644 index 00000000000..7ced0ae3253 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "subchart.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). +*/}} +{{- define "subchart.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml new file mode 100644 index 00000000000..f3075de53e3 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "subchart.name" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "subchart.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.pullPolicy }} + command: ["/bin/bash", "-c", "--" ] + args: ["while true; do sleep 30; done;"] + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml new file mode 100644 index 00000000000..127987f69d9 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "subchart.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "subchart.fullname" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml new file mode 100644 index 00000000000..80bb3759b95 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "subchart.fullname" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "subchart.name" . }} + release: {{ .Release.Name }} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml new file mode 100644 index 00000000000..e930d90bd76 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml @@ -0,0 +1,40 @@ +# Default values for skaffold-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +nameOverride: "subchart" +replicaCount: 1 +image: nginx:stable +# This is the helm convention on declaring images +# image: +# repository: nginx +# tag: stable +# pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - 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 diff --git a/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml b/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml new file mode 100644 index 00000000000..14601dde3a6 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml @@ -0,0 +1,3 @@ +dependencies: + - name: subchart + condition: subchart.enabled diff --git a/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl b/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl new file mode 100644 index 00000000000..537a7399829 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "skaffold-helm.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). +*/}} +{{- define "skaffold-helm.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml b/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml new file mode 100644 index 00000000000..02b76c5ec04 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "skaffold-helm.name" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "skaffold-helm.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.pullPolicy }} + command: ["/bin/bash", "-c", "--" ] + args: ["while true; do sleep 30; done;"] + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml b/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml new file mode 100644 index 00000000000..87fe1e813e6 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "skaffold-helm.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "skaffold-helm.fullname" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml b/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml new file mode 100644 index 00000000000..da7b3ef867b --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "skaffold-helm.fullname" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "skaffold-helm.name" . }} + release: {{ .Release.Name }} diff --git a/examples/helm-deployment-dependencies/skaffold-helm/values.yaml b/examples/helm-deployment-dependencies/skaffold-helm/values.yaml new file mode 100644 index 00000000000..49dfad48c72 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold-helm/values.yaml @@ -0,0 +1,42 @@ +# Default values for skaffold-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: nginx:stable +# This is the helm convention on declaring images +# image: +# repository: nginx +# tag: stable +# pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - 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 + +subchart: + enabled: true diff --git a/examples/helm-deployment-dependencies/skaffold.yaml b/examples/helm-deployment-dependencies/skaffold.yaml new file mode 100644 index 00000000000..c4af62b8002 --- /dev/null +++ b/examples/helm-deployment-dependencies/skaffold.yaml @@ -0,0 +1,28 @@ +apiVersion: skaffold/v1beta5 +kind: Config +build: + tagPolicy: + sha256: {} + artifacts: + - image: gcr.io/k8s-skaffold/skaffold-helm +deploy: + helm: + releases: + - name: skaffold-helm + chartPath: skaffold-helm + #wait: true + #valuesFiles: + #- helm-skaffold-values.yaml + skipBuildDependencies: true # Skip helm dep build + values: + image: gcr.io/k8s-skaffold/skaffold-helm + "skaffold-helm-subchart.image": gcr.io/k8s-skaffold/skaffold-helm + #recreatePods will pass --recreate-pods to helm upgrade + #recreatePods: true + #overrides builds an override values.yaml file to run with the helm deploy + #overrides: + # some: + # key: someValue + #setValues get appended to the helm deploy with --set. + #setValues: + #some.key: someValue diff --git a/integration/examples/helm-deployment-dependencies/Dockerfile b/integration/examples/helm-deployment-dependencies/Dockerfile new file mode 100644 index 00000000000..75eca2cb8ef --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/Dockerfile @@ -0,0 +1 @@ +FROM nginx:stable diff --git a/integration/examples/helm-deployment-dependencies/README.adoc b/integration/examples/helm-deployment-dependencies/README.adoc new file mode 100644 index 00000000000..9a1cff3e1a1 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/README.adoc @@ -0,0 +1,25 @@ +=== Example: helm-dependencies +:icons: font + +==== Deploy helm charts with local dependencies + +This example follows the link:{github-repo-tree}/examples/helm-deployment-dependencies[helm] example, but with a local chart as a depenency. + +The `skipBuildDependencies` option is used to skip the `helm dep build` command. This must be disabled for charts with local dependencies. + +The image can be passed to the subchart using the standard Helm format of `subchart-name.value`. + +``` +deploy: + helm: + releases: + - name: skaffold-helm + chartPath: skaffold-helm + namespace: skaffold + skipBuildDependencies: true # Skip helm dep build + values: + image: skaffold-helm + "subchart.image": gcr.io/k8s-skaffold/skaffold-helm # Set image for subchart + valuesFiles: + - helm-values-file.yaml +``` diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/.helmignore b/integration/examples/helm-deployment-dependencies/skaffold-helm/.helmignore new file mode 100644 index 00000000000..f0c13194444 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml new file mode 100644 index 00000000000..f4fcfadbec9 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: skaffold-helm +version: 0.1.0 diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore new file mode 100644 index 00000000000..f0c13194444 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml new file mode 100644 index 00000000000..3879caeaabd --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: subchart +version: 0.1.0 diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl new file mode 100644 index 00000000000..7ced0ae3253 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "subchart.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). +*/}} +{{- define "subchart.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml new file mode 100644 index 00000000000..f3075de53e3 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "subchart.name" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "subchart.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.pullPolicy }} + command: ["/bin/bash", "-c", "--" ] + args: ["while true; do sleep 30; done;"] + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml new file mode 100644 index 00000000000..127987f69d9 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "subchart.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "subchart.fullname" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml new file mode 100644 index 00000000000..80bb3759b95 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "subchart.fullname" . }} + labels: + app: {{ template "subchart.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "subchart.name" . }} + release: {{ .Release.Name }} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml new file mode 100644 index 00000000000..e930d90bd76 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/charts/subchart/values.yaml @@ -0,0 +1,40 @@ +# Default values for skaffold-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +nameOverride: "subchart" +replicaCount: 1 +image: nginx:stable +# This is the helm convention on declaring images +# image: +# repository: nginx +# tag: stable +# pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - 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 diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml new file mode 100644 index 00000000000..14601dde3a6 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/requirements.yaml @@ -0,0 +1,3 @@ +dependencies: + - name: subchart + condition: subchart.enabled diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl new file mode 100644 index 00000000000..537a7399829 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "skaffold-helm.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). +*/}} +{{- define "skaffold-helm.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml new file mode 100644 index 00000000000..02b76c5ec04 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "skaffold-helm.name" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "skaffold-helm.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.pullPolicy }} + command: ["/bin/bash", "-c", "--" ] + args: ["while true; do sleep 30; done;"] + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml new file mode 100644 index 00000000000..87fe1e813e6 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "skaffold-helm.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "skaffold-helm.fullname" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml new file mode 100644 index 00000000000..da7b3ef867b --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "skaffold-helm.fullname" . }} + labels: + app: {{ template "skaffold-helm.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "skaffold-helm.name" . }} + release: {{ .Release.Name }} diff --git a/integration/examples/helm-deployment-dependencies/skaffold-helm/values.yaml b/integration/examples/helm-deployment-dependencies/skaffold-helm/values.yaml new file mode 100644 index 00000000000..49dfad48c72 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold-helm/values.yaml @@ -0,0 +1,42 @@ +# Default values for skaffold-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: nginx:stable +# This is the helm convention on declaring images +# image: +# repository: nginx +# tag: stable +# pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - 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 + +subchart: + enabled: true diff --git a/integration/examples/helm-deployment-dependencies/skaffold.yaml b/integration/examples/helm-deployment-dependencies/skaffold.yaml new file mode 100644 index 00000000000..c4af62b8002 --- /dev/null +++ b/integration/examples/helm-deployment-dependencies/skaffold.yaml @@ -0,0 +1,28 @@ +apiVersion: skaffold/v1beta5 +kind: Config +build: + tagPolicy: + sha256: {} + artifacts: + - image: gcr.io/k8s-skaffold/skaffold-helm +deploy: + helm: + releases: + - name: skaffold-helm + chartPath: skaffold-helm + #wait: true + #valuesFiles: + #- helm-skaffold-values.yaml + skipBuildDependencies: true # Skip helm dep build + values: + image: gcr.io/k8s-skaffold/skaffold-helm + "skaffold-helm-subchart.image": gcr.io/k8s-skaffold/skaffold-helm + #recreatePods will pass --recreate-pods to helm upgrade + #recreatePods: true + #overrides builds an override values.yaml file to run with the helm deploy + #overrides: + # some: + # key: someValue + #setValues get appended to the helm deploy with --set. + #setValues: + #some.key: someValue diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index af44b6ff573..c1cc91ae064 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -171,6 +171,9 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates } } + // Dependency builds should be skipped when trying to install a chart + // with local dependencies in the chart folder, e.g. the istio helm chart. + // This decision is left to the user. if !r.SkipBuildDependencies { // First build dependencies. logrus.Infof("Building helm dependencies...") diff --git a/pkg/skaffold/deploy/helm_test.go b/pkg/skaffold/deploy/helm_test.go index 29d0762c102..54edbcd471e 100644 --- a/pkg/skaffold/deploy/helm_test.go +++ b/pkg/skaffold/deploy/helm_test.go @@ -85,6 +85,23 @@ var testDeployRecreatePodsConfig = &latest.HelmDeploy{ }, } +var testDeploySkipBuildDependenciesConfig = &latest.HelmDeploy{ + Releases: []latest.HelmRelease{ + { + Name: "skaffold-helm", + ChartPath: "examples/test", + Values: map[string]string{ + "image": "skaffold-helm", + }, + Overrides: schemautil.HelmOverrides{map[string]interface{}{"foo": "bar"}}, + SetValues: map[string]string{ + "some.key": "somevalue", + }, + SkipBuildDependencies: true, + }, + }, +} + var testDeployHelmStyleConfig = &latest.HelmDeploy{ Releases: []latest.HelmRelease{ { @@ -276,6 +293,12 @@ func TestHelmDeploy(t *testing.T) { deployer: NewHelmDeployer(testDeployRecreatePodsConfig, testKubeContext, testNamespace, ""), builds: testBuilds, }, + { + description: "deploy success with skipBuildDependencies", + cmd: &MockHelm{t: t}, + deployer: NewHelmDeployer(testDeploySkipBuildDependenciesConfig, testKubeContext, testNamespace, ""), + builds: testBuilds, + }, { description: "deploy error unmatched parameter", cmd: &MockHelm{t: t},