mirror of
https://github.com/k8s-at-home/charts.git
synced 2025-01-24 16:09:08 +00:00
[common] Add capabilities to determine apiVersion (#116)
* [common] Add capabilities to determine apiVersion * [common] Add capabilities to determine apiVersion
This commit is contained in:
parent
45c9f3c39e
commit
2b158892e3
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
{{- define "common.deployment" -}}
|
||||
apiVersion: apps/v1
|
||||
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ template "common.names.fullname" . }}
|
||||
|
@ -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" . }})
|
||||
|
@ -1,5 +1,5 @@
|
||||
{{- define "common.statefulset" -}}
|
||||
apiVersion: apps/v1
|
||||
apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ template "common.names.fullname" . }}
|
||||
|
@ -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 }}
|
||||
|
32
charts/common/templates/lib/chart/_capabilities.tpl
Normal file
32
charts/common/templates/lib/chart/_capabilities.tpl
Normal 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 -}}
|
@ -30,7 +30,7 @@ service:
|
||||
type: ClusterIP
|
||||
# Specify the default port information
|
||||
port:
|
||||
portNumber: ""
|
||||
port: ""
|
||||
name: http
|
||||
protocol: TCP
|
||||
targetPort: http
|
||||
|
Loading…
Reference in New Issue
Block a user