ref(*): Improve and fix scaffold chart and API versions (#6426)

* Use `apps/v1` for Deployment
* Reformat comments
* Consistently use `nindent` and indent properly
* Introduce named template for selector labels
* Fix label selector in `NOTES.txt`

Signed-off-by: Reinhard Naegele <unguiculus@gmail.com>
pull/6455/head
Reinhard Nägele 5 years ago committed by Martin Hickey
parent 1f6c80ca59
commit 38e41e12c9

@ -20,7 +20,7 @@ spec:
type: ClusterIP type: ClusterIP
--- ---
# Source: chart-with-template-lib-archive-dep/templates/deployment.yaml # Source: chart-with-template-lib-archive-dep/templates/deployment.yaml
apiVersion: apps/v1beta2 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: RELEASE-NAME-chart-with-template-lib-archive-dep name: RELEASE-NAME-chart-with-template-lib-archive-dep

@ -20,7 +20,7 @@ spec:
type: ClusterIP type: ClusterIP
--- ---
# Source: chart-with-template-lib-dep/templates/deployment.yaml # Source: chart-with-template-lib-dep/templates/deployment.yaml
apiVersion: apps/v1beta2 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: RELEASE-NAME-chart-with-template-lib-dep name: RELEASE-NAME-chart-with-template-lib-dep

@ -1,4 +1,4 @@
apiVersion: apps/v1beta2 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ template "chart-with-lib-dep.fullname" . }} name: {{ template "chart-with-lib-dep.fullname" . }}

@ -1,4 +1,4 @@
apiVersion: apps/v1beta2 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ template "chart-with-template-lib-archive-dep.fullname" . }} name: {{ template "chart-with-template-lib-archive-dep.fullname" . }}

@ -1,4 +1,4 @@
apiVersion: apps/v1beta2 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ template "chart-with-template-lib-dep.fullname" . }} name: {{ template "chart-with-template-lib-dep.fullname" . }}

@ -105,9 +105,9 @@ ingress:
paths: [] paths: []
tls: [] tls: []
# - secretName: chart-example-tls # - secretName: chart-example-tls
# hosts: # hosts:
# - chart-example.local # - chart-example.local
resources: {} resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious # We usually recommend not to specify default resources and to leave this as a conscious
@ -115,11 +115,11 @@ resources: {}
# resources, such as Minikube. If you do want to specify resources, uncomment the following # 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:'. # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits: # limits:
# cpu: 100m # cpu: 100m
# memory: 128Mi # memory: 128Mi
# requests: # requests:
# cpu: 100m # cpu: 100m
# memory: 128Mi # memory: 128Mi
nodeSelector: {} nodeSelector: {}
@ -159,7 +159,7 @@ kind: Ingress
metadata: metadata:
name: {{ $fullName }} name: {{ $fullName }}
labels: labels:
{{ include "<CHARTNAME>.labels" . | indent 4 }} {{- include "<CHARTNAME>.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }} {{- with .Values.ingress.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}
@ -190,23 +190,21 @@ spec:
{{- end }} {{- end }}
` `
const defaultDeployment = `apiVersion: apps/v1beta2 const defaultDeployment = `apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ template "<CHARTNAME>.fullname" . }} name: {{ include "<CHARTNAME>.fullname" . }}
labels: labels:
{{ include "<CHARTNAME>.labels" . | indent 4 }} {{- include "<CHARTNAME>.labels" . | nindent 4 }}
spec: spec:
replicas: {{ .Values.replicaCount }} replicas: {{ .Values.replicaCount }}
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{- include "<CHARTNAME>.selectorLabels" . | nindent 6 }}
app.kubernetes.io/instance: {{ .Release.Name }}
template: template:
metadata: metadata:
labels: labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{- include "<CHARTNAME>.selectorLabels" . | nindent 8 }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec: spec:
containers: containers:
- name: {{ .Chart.Name }} - name: {{ .Chart.Name }}
@ -225,27 +223,27 @@ spec:
path: / path: /
port: http port: http
resources: resources:
{{ toYaml .Values.resources | indent 12 }} {{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }} {{- with .Values.nodeSelector }}
nodeSelector: nodeSelector:
{{ toYaml . | indent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
{{- with .Values.affinity }} {{- with .Values.affinity }}
affinity: affinity:
{{ toYaml . | indent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
{{- with .Values.tolerations }} {{- with .Values.tolerations }}
tolerations: tolerations:
{{ toYaml . | indent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
` `
const defaultService = `apiVersion: v1 const defaultService = `apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: {{ template "<CHARTNAME>.fullname" . }} name: {{ include "<CHARTNAME>.fullname" . }}
labels: labels:
{{ include "<CHARTNAME>.labels" . | indent 4 }} {{- include "<CHARTNAME>.labels" . | nindent 4 }}
spec: spec:
type: {{ .Values.service.type }} type: {{ .Values.service.type }}
ports: ports:
@ -254,8 +252,7 @@ spec:
protocol: TCP protocol: TCP
name: http name: http
selector: selector:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} {{- include "<CHARTNAME>.selectorLabels" . | nindent 4 }}
app.kubernetes.io/instance: {{ .Release.Name }}
` `
const defaultNotes = `1. Get the application URL by running these commands: const defaultNotes = `1. Get the application URL by running these commands:
@ -266,16 +263,16 @@ const defaultNotes = `1. Get the application URL by running these commands:
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- else if contains "NodePort" .Values.service.type }} {{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "<CHARTNAME>.fullname" . }}) export NODE_PORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "<CHARTNAME>.fullname" . }})
export NODE_IP=$(kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_IP=$(kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }} {{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available. 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 {{ template "<CHARTNAME>.fullname" . }}' You can watch the status of by running 'kubectl get svc -w {{ include "<CHARTNAME>.fullname" . }}'
export SERVICE_IP=$(kubectl get svc {{ template "<CHARTNAME>.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') export SERVICE_IP=$(kubectl get svc {{ include "<CHARTNAME>.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }} echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }} {{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods -l "app={{ template "<CHARTNAME>.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export POD_NAME=$(kubectl get pods -l "app.kubernetes.io/name={{ include "<CHARTNAME>.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" echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80 kubectl port-forward $POD_NAME 8080:80
{{- end }} {{- end }}
@ -318,14 +315,21 @@ Create chart name and version as used by the chart label.
Common labels Common labels
*/}} */}}
{{- define "<CHARTNAME>.labels" -}} {{- define "<CHARTNAME>.labels" -}}
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }} helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }} {{ include "<CHARTNAME>.selectorLabels" . }}
{{- if .Chart.AppVersion }} {{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }} {{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}} {{- end -}}
{{/*
Selector labels
*/}}
{{- define "<CHARTNAME>.selectorLabels" -}}
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
` `
// CreateFrom creates a new chart, but scaffolds it from the src chart. // CreateFrom creates a new chart, but scaffolds it from the src chart.

Loading…
Cancel
Save