Skip to content

Commit

Permalink
Merge pull request #3376 from cloudfoundry-incubator/helm-fix-reuse-v…
Browse files Browse the repository at this point in the history
…alues

Helm Chart Fix for --reuse-values
  • Loading branch information
nwmac authored Feb 7, 2019
2 parents 7f5b386 + 8f2004a commit b4fa724
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
19 changes: 19 additions & 0 deletions deploy/ci/automation/helmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ helm install ${CHART_FILE} --name ${NAME} --namespace ${NAMESPACE} --set console
waitForHelmRelease
checkVersion console-0.1.0

deleteRelease

# Upgrade test using --reuse-values

# Install latest version first
log "Testing Upgrade using --reuse-values"
log "Installing latest release"
helm install ${HELM_REPO_NAME}/console --name ${NAME} --namespace ${NAMESPACE}

# Wait for the chart to deploy and be ready
waitForHelmRelease

log "Upgrading using --reuse-values"
helm upgrade ${NAME} ${HELM_TMP}/console --recreate-pods --debug --reuse-values

waitForHelmRelease
# Should have used same values as before
checkVersion console-0.2.0

# All okay
deleteRelease

Expand Down
5 changes: 4 additions & 1 deletion deploy/ci/tasks/dev-releases/create-chart-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ patchHelmChart () {
sed -i -e 's/hostname: docker.io/hostname: '"${DOCKER_REG}"'/g' ${CHART_PATH}/values.yaml

sed -i -e 's/version: 0.1.0/version: '"${CHART_VERSION}"'/g' ${CHART_PATH}/Chart.yaml
sed -i -e 's/appVersion: 0.1.0/appVersion: '"${APP_VERSION}"'/g' ${CHART_PATH}/Chart.yaml
sed -i -e 's/appVersion: 0.1.0/appVersion: '"${APP_VERSION}"'/g' ${CHART_PATH}/Chart.yaml

# Patch the console image tag in place - otherwise --reuse-values won't work with helm upgrade
sed -i -e 's/{{.Values.consoleVersion}}/'"${TAG}"'/g' ${CHART_PATH}/templates/deployment.yaml
}

patchHelmChartDev () {
Expand Down
34 changes: 26 additions & 8 deletions deploy/kubernetes/console/templates/__helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@ This will do the following:
4. Check for new Console External IPS
*/}}
{{- define "service.externalIPs" -}}
{{- if .Values.kube.external_ip -}}
{{- if .Values.kube.external_ip }}
externalIPs:
{{- printf "\n - %s" .Values.kube.external_ip | indent 3 -}}
{{- else if .Values.console.externalIP -}}
{{- printf "\n" -}}
{{- else if .Values.console.externalIP }}
externalIPs:
{{- printf "\n - %s" .Values.console.externalIP | indent 3 -}}
{{- else if .Values.kube.external_ips -}}
{{- printf "\n" -}}
{{- else if .Values.kube.external_ips }}
externalIPs:
{{- range .Values.kube.external_ips -}}
{{ printf "\n- %s" . | indent 4 -}}
{{- printf "\n- %s" . | indent 4 -}}
{{- end -}}
{{- else if .Values.console.service.externalIPs -}}
{{- printf "\n" -}}
{{- else if .Values.console.service -}}
{{- if .Values.console.service.externalIPs }}
externalIPs:
{{- range .Values.console.service.externalIPs -}}
{{ printf "\n- %s" . | indent 4 -}}
{{ printf "\n- %s" . | indent 4 }}
{{- end -}}
{{- printf "\n" -}}
{{- end -}}
{{- end -}}
{{ end }}


{{/*
Expand All @@ -51,7 +61,11 @@ Service type:
{{- if or .Values.useLb .Values.services.loadbalanced -}}
LoadBalancer
{{- else -}}
{{- printf "%s" .Values.console.service.type -}}
{{- if .Values.console.service -}}
{{- default "ClusterIP" .Values.console.service.type -}}
{{- else -}}
ClusterIP
{{- end -}}
{{- end -}}
{{- end -}}

Expand All @@ -63,6 +77,10 @@ Service port:
{{- if and .Values.kube.external_ips .Values.kube.external_console_https_port -}}
{{ printf "%v" .Values.kube.external_console_https_port }}
{{- else -}}
{{ .Values.console.service.servicePort }}
{{- if .Values.console.service -}}
{{ default 443 .Values.console.service.servicePort}}
{{- else -}}
443
{{- end -}}
{{- end -}}
{{- end -}}
40 changes: 28 additions & 12 deletions deploy/kubernetes/console/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,63 +1,79 @@
apiVersion: v1
kind: Service
metadata:
{{- if .Values.console.service -}}
{{- if .Values.console.service.annotations }}
annotations:
{{ toYaml .Values.console.service.annotations | indent 4 }}
{{- end }}
{{- end }}
labels:
app.kubernetes.io/name: "stratos"
app.kubernetes.io/instance: "{{ .Release.Name }}"
app.kubernetes.io/version: "{{ .Chart.AppVersion }}"
app.kubernetes.io/component: "console-ext-service"
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
name: "{{ .Release.Name }}-ext"
name: "{{ .Release.Name }}-ui-ext"
spec:
selector:
app: "{{ .Release.Name }}"
component: stratos
{{- if .Values.console.service -}}
{{- if .Values.console.service.clusterIP }}
clusterIP: {{ .Values.console.service.clusterIP }}
{{- end -}}
{{- end }}
{{- if or .Values.console.service.externalIPs .Values.kube.external_ip .Values.console.externalIP .Values.kube.external_ips }}
externalIPs:
{{ template "service.externalIPs" . }}
{{- end }}
{{ template "service.externalIPs" . }}
{{- if .Values.console.service -}}
{{- if .Values.console.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.console.service.loadBalancerIP }}
{{- end }}
{{ end -}}
{{- end -}}
{{- if .Values.console.service -}}
{{- if .Values.console.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- range $cidr := .Values.console.service.loadBalancerSourceRanges }}
- {{ $cidr }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.console.service -}}
{{- if .Values.console.service.externalName }}
externalName: {{ .Values.console.service.externalName }}
{{- end }}
{{ end }}
{{- end -}}

# Note: HTTP Port is optional - HTTPS port is always included
# HTTP Service (optional)
type: {{ template "service.serviceType" . }}
ports:
{{- if .Values.console.service }}
{{- if .Values.console.service.http -}}
{{- if .Values.console.service.http.enabled }}
- name: http
port: {{ .Values.console.service.http.servicePort }}
port: {{ default 80 .Values.console.service.http.servicePort }}
protocol: TCP
targetPort: 80
{{- if .Values.console.service.http.nodePort }}
nodePort: {{ .Values.console.service.http.nodePort }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end }}
# HTTPS Service
- name: https
port: {{ template "service.servicePort" . }}
protocol: TCP
targetPort: 443
{{- if .Values.console.service.nodePort }}
{{- if .Values.console.service -}}
{{- if and .Values.console.service.nodePort (eq .Values.console.service.type "NodePort") }}
nodePort: {{ .Values.console.service.nodePort }}
{{ else if .Release.IsUpgrade }}
nodePort:
{{- end }}
{{ else if .Release.IsUpgrade }}
nodePort:
{{- end }}
type: {{ template "service.serviceType" . }}

---
apiVersion: v1
kind: Service
Expand Down

0 comments on commit b4fa724

Please sign in to comment.