overhaul ingress configuration
This commit is contained in:
parent
1ac39a6f5d
commit
37b92f265f
@ -392,3 +392,15 @@ https
|
|||||||
{{- define "gitea.serviceAccountName" -}}
|
{{- define "gitea.serviceAccountName" -}}
|
||||||
{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }}
|
{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "ingress.annotations" -}}
|
||||||
|
{{- if .Values.ingress.annotations }}
|
||||||
|
annotations:
|
||||||
|
{{- $tp := typeOf .Values.ingress.annotations }}
|
||||||
|
{{- if eq $tp "string" }}
|
||||||
|
{{- tpl .Values.ingress.annotations . | nindent 4 }}
|
||||||
|
{{- else }}
|
||||||
|
{{- toYaml .Values.ingress.annotations | nindent 4 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
@ -1,24 +1,14 @@
|
|||||||
{{- if .Values.ingress.enabled -}}
|
{{- if .Values.ingress.enabled -}}
|
||||||
{{- $fullName := include "gitea.fullname" . -}}
|
{{- $fullName := include "gitea.fullname" . -}}
|
||||||
{{- $httpPort := .Values.service.http.port -}}
|
{{- $httpPort := .Values.service.http.port -}}
|
||||||
{{- $apiVersion := "extensions/v1beta1" -}}
|
{{- $pathType := .Values.ingress.pathType -}}
|
||||||
{{- if .Values.ingress.apiVersion -}}
|
apiVersion: networking.k8s.io/v1
|
||||||
{{- $apiVersion = .Values.ingress.apiVersion -}}
|
|
||||||
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" -}}
|
|
||||||
{{- $apiVersion = "networking.k8s.io/v1" }}
|
|
||||||
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1/Ingress" -}}
|
|
||||||
{{- $apiVersion = "networking.k8s.io/v1beta1" }}
|
|
||||||
{{- end }}
|
|
||||||
apiVersion: {{ $apiVersion }}
|
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $fullName }}
|
name: {{ template "gitea.fullname" . }}
|
||||||
labels:
|
labels:
|
||||||
{{- include "gitea.labels" . | nindent 4 }}
|
{{- include "gitea.labels" . | nindent 4 }}
|
||||||
annotations:
|
{{- template "ingress.annotations" . }}
|
||||||
{{- range $key, $value := .Values.ingress.annotations }}
|
|
||||||
{{ $key }}: {{ $value | quote }}
|
|
||||||
{{- end }}
|
|
||||||
spec:
|
spec:
|
||||||
{{- if .Values.ingress.className }}
|
{{- if .Values.ingress.className }}
|
||||||
ingressClassName: {{ tpl .Values.ingress.className . }}
|
ingressClassName: {{ tpl .Values.ingress.className . }}
|
||||||
@ -38,21 +28,14 @@ spec:
|
|||||||
- host: {{ tpl .host $ | quote }}
|
- host: {{ tpl .host $ | quote }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
{{- range .paths }}
|
{{- range (.paths | default (list "/")) }}
|
||||||
- path: {{ .path }}
|
- path: {{ . }}
|
||||||
{{- if and .pathType (eq $apiVersion "networking.k8s.io/v1") }}
|
pathType: {{ $pathType }}
|
||||||
pathType: {{ .pathType }}
|
|
||||||
{{- end }}
|
|
||||||
backend:
|
backend:
|
||||||
{{- if eq $apiVersion "networking.k8s.io/v1" }}
|
|
||||||
service:
|
service:
|
||||||
name: {{ $fullName }}-http
|
name: {{ $fullName }}-http
|
||||||
port:
|
port:
|
||||||
number: {{ $httpPort }}
|
number: {{ $httpPort }}
|
||||||
{{- else }}
|
|
||||||
serviceName: {{ $fullName }}-http
|
|
||||||
servicePort: {{ $httpPort }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
93
unittests/ingress/basic.yaml
Normal file
93
unittests/ingress/basic.yaml
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
suite: Test ingress.yaml
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: should enable ingress when ingress.enabled is true
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.apiVersion: networking.k8s.io/v1
|
||||||
|
ingress.annotations:
|
||||||
|
kubernetes.io/ingress.class: nginx
|
||||||
|
ingress.className: nginx
|
||||||
|
ingress.tls:
|
||||||
|
- hosts:
|
||||||
|
- example.com
|
||||||
|
secretName: tls-secret
|
||||||
|
ingress.hosts:
|
||||||
|
- host: example.com
|
||||||
|
paths: ["/"]
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: metadata.name
|
||||||
|
value: RELEASE-NAME-gitea
|
||||||
|
- matchRegex:
|
||||||
|
path: apiVersion
|
||||||
|
pattern: networking.k8s.io/v1
|
||||||
|
- equal:
|
||||||
|
path: spec.ingressClassName
|
||||||
|
value: nginx
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].secretName
|
||||||
|
value: tls-secret
|
||||||
|
- equal:
|
||||||
|
path: metadata.annotations["kubernetes.io/ingress.class"]
|
||||||
|
value: nginx
|
||||||
|
|
||||||
|
- it: should not create ingress when ingress.enabled is false
|
||||||
|
set:
|
||||||
|
ingress.enabled: false
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 0
|
||||||
|
|
||||||
|
- it: Ingress Class using TPL
|
||||||
|
set:
|
||||||
|
global.ingress.className: "ingress-class"
|
||||||
|
ingress.className: "{{ .Values.global.ingress.className }}"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "some-host"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "some-host"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.ingressClassName
|
||||||
|
value: "ingress-class"
|
||||||
|
|
||||||
|
- it: hostname using TPL
|
||||||
|
set:
|
||||||
|
global.giteaHostName: "gitea.example.com"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "{{ .Values.global.giteaHostName }}"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "gitea.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "gitea.example.com"
|
@ -1,28 +1,7 @@
|
|||||||
suite: ingress template
|
suite: Test ingress tpl use
|
||||||
release:
|
|
||||||
name: gitea-unittests
|
|
||||||
namespace: testing
|
|
||||||
templates:
|
templates:
|
||||||
- templates/gitea/ingress.yaml
|
- templates/gitea/ingress.yaml
|
||||||
tests:
|
tests:
|
||||||
- it: hostname using TPL
|
|
||||||
set:
|
|
||||||
global.giteaHostName: "gitea.example.com"
|
|
||||||
ingress.enabled: true
|
|
||||||
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
|
||||||
ingress.tls:
|
|
||||||
- secretName: gitea-tls
|
|
||||||
hosts:
|
|
||||||
- "{{ .Values.global.giteaHostName }}"
|
|
||||||
asserts:
|
|
||||||
- isKind:
|
|
||||||
of: Ingress
|
|
||||||
- equal:
|
|
||||||
path: spec.tls[0].hosts[0]
|
|
||||||
value: "gitea.example.com"
|
|
||||||
- equal:
|
|
||||||
path: spec.rules[0].host
|
|
||||||
value: "gitea.example.com"
|
|
||||||
- it: Ingress Class using TPL
|
- it: Ingress Class using TPL
|
||||||
set:
|
set:
|
||||||
global.ingress.className: "ingress-class"
|
global.ingress.className: "ingress-class"
|
||||||
@ -45,3 +24,22 @@ tests:
|
|||||||
- equal:
|
- equal:
|
||||||
path: spec.ingressClassName
|
path: spec.ingressClassName
|
||||||
value: "ingress-class"
|
value: "ingress-class"
|
||||||
|
|
||||||
|
- it: hostname using TPL
|
||||||
|
set:
|
||||||
|
global.giteaHostName: "gitea.example.com"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "{{ .Values.global.giteaHostName }}"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "gitea.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "gitea.example.com"
|
@ -161,15 +161,14 @@ ingress:
|
|||||||
enabled: false
|
enabled: false
|
||||||
# className: nginx
|
# className: nginx
|
||||||
className:
|
className:
|
||||||
|
pathType: Prefix
|
||||||
annotations:
|
annotations:
|
||||||
{}
|
{}
|
||||||
# kubernetes.io/ingress.class: nginx
|
# kubernetes.io/ingress.class: nginx
|
||||||
# kubernetes.io/tls-acme: "true"
|
# kubernetes.io/tls-acme: "true"
|
||||||
hosts:
|
hosts:
|
||||||
- host: git.example.com
|
- host: git.example.com
|
||||||
paths:
|
paths: []
|
||||||
- path: /
|
|
||||||
pathType: Prefix
|
|
||||||
tls: []
|
tls: []
|
||||||
# - secretName: chart-example-tls
|
# - secretName: chart-example-tls
|
||||||
# hosts:
|
# hosts:
|
||||||
|
Loading…
Reference in New Issue
Block a user