[common] Add capabilities to determine apiVersion (#116)

* [common] Add capabilities to determine apiVersion

* [common] Add capabilities to determine apiVersion
This commit is contained in:
Bernd Schörgers 2020-11-07 14:17:31 +01:00 committed by GitHub
parent 45c9f3c39e
commit 2b158892e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 25 deletions

View File

@ -2,7 +2,7 @@ apiVersion: v2
name: common name: common
description: Function library for k8s-at-home charts description: Function library for k8s-at-home charts
type: library type: library
version: 1.0.3 version: 1.0.4
keywords: keywords:
- k8s-at-home - k8s-at-home
- common - common

View File

@ -1,5 +1,5 @@
{{- define "common.deployment" -}} {{- define "common.deployment" -}}
apiVersion: apps/v1 apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ template "common.names.fullname" . }} name: {{ template "common.names.fullname" . }}

View File

@ -2,11 +2,11 @@
Default NOTES.txt content. Default NOTES.txt content.
*/}} */}}
{{- define "common.notes.defaultNotes" -}} {{- define "common.notes.defaultNotes" -}}
{{- $svcPort := .Values.service.port -}} {{- $svcPort := .Values.service.port.port -}}
1. Get the application URL by running these commands: 1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }} {{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }} {{- 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 }} {{- end }}
{{- else if contains "NodePort" .Values.service.type }} {{- 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" . }}) export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }})

View File

@ -1,5 +1,5 @@
{{- define "common.statefulset" -}} {{- define "common.statefulset" -}}
apiVersion: apps/v1 apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
kind: StatefulSet kind: StatefulSet
metadata: metadata:
name: {{ template "common.names.fullname" . }} name: {{ template "common.names.fullname" . }}

View File

@ -1,6 +1,4 @@
{{- define "common.classes.ingress" -}} {{- 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" . -}} {{- $ingressName := include "common.names.fullname" . -}}
{{- $values := .Values.ingress -}} {{- $values := .Values.ingress -}}
{{- if hasKey . "ObjectValues" -}} {{- if hasKey . "ObjectValues" -}}
@ -12,13 +10,7 @@
{{- $ingressName = printf "%v-%v" $ingressName $values.nameSuffix -}} {{- $ingressName = printf "%v-%v" $ingressName $values.nameSuffix -}}
{{ end -}} {{ end -}}
{{- $svcPort := $values.svcPort -}} {{- $svcPort := $values.svcPort -}}
{{- if $apiv1 -}} apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
apiVersion: networking.k8s.io/v1
{{- else if $apiv1beta1 -}}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{ end }}
kind: Ingress kind: Ingress
metadata: metadata:
name: {{ $ingressName }} name: {{ $ingressName }}
@ -46,19 +38,9 @@ spec:
paths: paths:
{{- range .paths }} {{- range .paths }}
- path: {{ .path }} - path: {{ .path }}
{{- if or $apiv1beta1 $apiv1 }}
pathType: {{ .pathType }}
{{- end }}
backend: backend:
{{- if $apiv1 }}
service:
name: {{ $ingressName }}
port:
name: {{ $svcPort }}
{{- else }}
serviceName: {{ $ingressName }} serviceName: {{ $ingressName }}
servicePort: {{ $svcPort }} servicePort: {{ $svcPort }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }}

View File

@ -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 -}}

View File

@ -30,7 +30,7 @@ service:
type: ClusterIP type: ClusterIP
# Specify the default port information # Specify the default port information
port: port:
portNumber: "" port: ""
name: http name: http
protocol: TCP protocol: TCP
targetPort: http targetPort: http