diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 0dca0d10..3204b9b2 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: common description: Function library for k8s-at-home charts type: library -version: 1.0.3 +version: 1.0.4 keywords: - k8s-at-home - common diff --git a/charts/common/templates/_deployment.tpl b/charts/common/templates/_deployment.tpl index f3543e10..92bdebc6 100644 --- a/charts/common/templates/_deployment.tpl +++ b/charts/common/templates/_deployment.tpl @@ -1,5 +1,5 @@ {{- define "common.deployment" -}} -apiVersion: apps/v1 +apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} kind: Deployment metadata: name: {{ template "common.names.fullname" . }} diff --git a/charts/common/templates/_notes.tpl b/charts/common/templates/_notes.tpl index 49340a84..07904900 100644 --- a/charts/common/templates/_notes.tpl +++ b/charts/common/templates/_notes.tpl @@ -2,11 +2,11 @@ Default NOTES.txt content. */}} {{- define "common.notes.defaultNotes" -}} -{{- $svcPort := .Values.service.port -}} +{{- $svcPort := .Values.service.port.port -}} 1. Get the application URL by running these commands: {{- if .Values.ingress.enabled }} {{- range .Values.ingress.hosts }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .host }}{{ (first .paths).path }} {{- end }} {{- else if contains "NodePort" .Values.service.type }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }}) diff --git a/charts/common/templates/_statefulset.tpl b/charts/common/templates/_statefulset.tpl index 1c432ff7..5f652fef 100644 --- a/charts/common/templates/_statefulset.tpl +++ b/charts/common/templates/_statefulset.tpl @@ -1,5 +1,5 @@ {{- define "common.statefulset" -}} -apiVersion: apps/v1 +apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }} kind: StatefulSet metadata: name: {{ template "common.names.fullname" . }} diff --git a/charts/common/templates/classes/_ingress.tpl b/charts/common/templates/classes/_ingress.tpl index 9a3d12b7..abce11ac 100644 --- a/charts/common/templates/classes/_ingress.tpl +++ b/charts/common/templates/classes/_ingress.tpl @@ -1,6 +1,4 @@ {{- define "common.classes.ingress" -}} -{{- $apiv1 := .Capabilities.APIVersions.Has "networking.k8s.io/v1" -}} -{{- $apiv1beta1 := .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}} {{- $ingressName := include "common.names.fullname" . -}} {{- $values := .Values.ingress -}} {{- if hasKey . "ObjectValues" -}} @@ -12,13 +10,7 @@ {{- $ingressName = printf "%v-%v" $ingressName $values.nameSuffix -}} {{ end -}} {{- $svcPort := $values.svcPort -}} -{{- if $apiv1 -}} -apiVersion: networking.k8s.io/v1 -{{- else if $apiv1beta1 -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else }} -apiVersion: extensions/v1beta1 -{{ end }} +apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} kind: Ingress metadata: name: {{ $ingressName }} @@ -46,19 +38,9 @@ spec: paths: {{- range .paths }} - path: {{ .path }} - {{- if or $apiv1beta1 $apiv1 }} - pathType: {{ .pathType }} - {{- end }} backend: - {{- if $apiv1 }} - service: - name: {{ $ingressName }} - port: - name: {{ $svcPort }} - {{- else }} serviceName: {{ $ingressName }} servicePort: {{ $svcPort }} - {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/common/templates/lib/chart/_capabilities.tpl b/charts/common/templates/lib/chart/_capabilities.tpl new file mode 100644 index 00000000..1aaf5044 --- /dev/null +++ b/charts/common/templates/lib/chart/_capabilities.tpl @@ -0,0 +1,32 @@ +{{/* +Return the appropriate apiVersion for deployment. +*/}} +{{- define "common.capabilities.deployment.apiVersion" -}} +{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "extensions/v1beta1" -}} +{{- else -}} +{{- print "apps/v1" -}} +{{- end -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for statefulset. +*/}} +{{- define "common.capabilities.statefulset.apiVersion" -}} +{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "apps/v1beta1" -}} +{{- else -}} +{{- print "apps/v1" -}} +{{- end -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for ingress. +*/}} +{{- define "common.capabilities.ingress.apiVersion" -}} +{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "extensions/v1beta1" -}} +{{- else -}} +{{- print "networking.k8s.io/v1beta1" -}} +{{- end -}} +{{- end -}} diff --git a/charts/common/values.yaml b/charts/common/values.yaml index c24ef155..132901ee 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -30,7 +30,7 @@ service: type: ClusterIP # Specify the default port information port: - portNumber: "" + port: "" name: http protocol: TCP targetPort: http