mirror of
https://github.com/k8s-at-home/charts.git
synced 2025-01-23 23:49:12 +00:00
[common] Add ingress unittest and tpl functionality (#568)
* Add support for tpl in ingress handling
This commit is contained in:
parent
1c7d6d403e
commit
11ef99d20a
@ -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: 2.4.0
|
version: 2.5.0
|
||||||
keywords:
|
keywords:
|
||||||
- k8s-at-home
|
- k8s-at-home
|
||||||
- common
|
- common
|
||||||
|
@ -6,7 +6,7 @@ Default NOTES.txt content.
|
|||||||
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 }}://{{ .host }}{{ (first .paths).path }}
|
http{{ if $.Values.ingress.tls }}s{{ end }}://{{- if .hostTpl }}{{ tpl .hostTpl $ }}{{ else }}{{ .host }}{{ end }}{{ (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" . }})
|
||||||
|
@ -38,12 +38,23 @@ spec:
|
|||||||
{{- range .hosts }}
|
{{- range .hosts }}
|
||||||
- {{ . | quote }}
|
- {{ . | quote }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- range .hostsTpl }}
|
||||||
|
- {{ tpl . $ | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .secretNameTpl }}
|
||||||
|
secretName: {{ tpl .secretNameTpl $ | quote}}
|
||||||
|
{{- else }}
|
||||||
secretName: {{ .secretName }}
|
secretName: {{ .secretName }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
rules:
|
rules:
|
||||||
{{- range $values.hosts }}
|
{{- range $values.hosts }}
|
||||||
|
{{- if .hostTpl }}
|
||||||
|
- host: {{ tpl .hostTpl $ | quote }}
|
||||||
|
{{- else }}
|
||||||
- host: {{ .host | quote }}
|
- host: {{ .host | quote }}
|
||||||
|
{{- end }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
{{- range .paths }}
|
{{- range .paths }}
|
||||||
|
@ -178,14 +178,21 @@ ingress:
|
|||||||
labels: {}
|
labels: {}
|
||||||
hosts:
|
hosts:
|
||||||
- host: chart-example.local
|
- host: chart-example.local
|
||||||
|
## Or a tpl that is evaluated
|
||||||
|
# hostTpl: '{{ include "common.names.fullname" . }}.{{ .Release.Namespace }}.{{ .Values.ingress.domainname }}'
|
||||||
paths:
|
paths:
|
||||||
- path: /
|
- path: /
|
||||||
# Ignored if not kubeVersion >= 1.14-0
|
# Ignored if not kubeVersion >= 1.14-0
|
||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
tls: []
|
tls: []
|
||||||
# - secretName: chart-example-tls
|
# - secretName: chart-example-tls
|
||||||
|
## Or if you need a dynamic secretname
|
||||||
|
# - secretNameTpl: '{{ include "common.names.fullname" . }}-ingress'
|
||||||
# hosts:
|
# hosts:
|
||||||
# - chart-example.local
|
# - chart-example.local
|
||||||
|
## Or a tpl that is evaluated
|
||||||
|
# hostTpl:
|
||||||
|
# - '{{ include "common.names.fullname" . }}.{{ .Release.Namespace }}.{{ .Values.ingress.domainname }}'
|
||||||
additionalIngresses: []
|
additionalIngresses: []
|
||||||
# - enabled: false
|
# - enabled: false
|
||||||
# nameSuffix: "api"
|
# nameSuffix: "api"
|
||||||
|
@ -186,5 +186,133 @@ class Test < ChartTest
|
|||||||
jq('.spec.volumeClaimTemplates[0].spec.storageClassName', resource('StatefulSet')).must_equal values[:volumeClaimTemplates][0][:storageClass]
|
jq('.spec.volumeClaimTemplates[0].spec.storageClassName', resource('StatefulSet')).must_equal values[:volumeClaimTemplates][0][:storageClass]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'ingress' do
|
||||||
|
it 'should be disabled when ingress.enabled: false' do
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
enabled: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chart.value values
|
||||||
|
assert_nil(resource('Ingress'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be enabled when ingress.enabled: true' do
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.value values
|
||||||
|
refute_nil(resource('Ingress'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ingress with hosts' do
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
hosts: [
|
||||||
|
{
|
||||||
|
host: 'hostname',
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: '/'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.value values
|
||||||
|
jq('.spec.rules[0].host', resource('Ingress')).must_equal values[:ingress][:hosts][0][:host]
|
||||||
|
jq('.spec.rules[0].http.paths[0].path', resource('Ingress')).must_equal values[:ingress][:hosts][0][:paths][0][:path]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ingress with hosts template is evaluated' do
|
||||||
|
expectedHostName = 'common-test.hostname'
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
hosts: [
|
||||||
|
{
|
||||||
|
hostTpl: '{{ .Release.Name }}.hostname',
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: '/'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.value values
|
||||||
|
jq('.spec.rules[0].host', resource('Ingress')).must_equal expectedHostName
|
||||||
|
jq('.spec.rules[0].http.paths[0].path', resource('Ingress')).must_equal values[:ingress][:hosts][0][:paths][0][:path]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ingress with hosts and tls' do
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
enabled: true,
|
||||||
|
hosts: [
|
||||||
|
{
|
||||||
|
host: 'hostname',
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: '/'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
tls: [
|
||||||
|
{
|
||||||
|
hosts: [ 'hostname' ],
|
||||||
|
secretName: 'hostname-secret-name'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.value values
|
||||||
|
jq('.spec.rules[0].host', resource('Ingress')).must_equal values[:ingress][:hosts][0][:host]
|
||||||
|
jq('.spec.rules[0].http.paths[0].path', resource('Ingress')).must_equal values[:ingress][:hosts][0][:paths][0][:path]
|
||||||
|
jq('.spec.tls[0].hosts[0]', resource('Ingress')).must_equal values[:ingress][:tls][0][:hosts][0]
|
||||||
|
jq('.spec.tls[0].secretName', resource('Ingress')).must_equal values[:ingress][:tls][0][:secretName]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ingress with hosts and tls templates is evaluated' do
|
||||||
|
expectedHostName = 'common-test.hostname'
|
||||||
|
expectedSecretName = 'common-test-hostname-secret-name'
|
||||||
|
values = {
|
||||||
|
ingress: {
|
||||||
|
enabled: true,
|
||||||
|
hosts: [
|
||||||
|
{
|
||||||
|
hostTpl: '{{ .Release.Name }}.hostname',
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: '/'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
tls: [
|
||||||
|
{
|
||||||
|
hostsTpl: [ '{{ .Release.Name }}.hostname' ],
|
||||||
|
secretNameTpl: '{{ .Release.Name }}-hostname-secret-name'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.value values
|
||||||
|
jq('.spec.rules[0].host', resource('Ingress')).must_equal expectedHostName
|
||||||
|
jq('.spec.rules[0].http.paths[0].path', resource('Ingress')).must_equal values[:ingress][:hosts][0][:paths][0][:path]
|
||||||
|
jq('.spec.tls[0].hosts[0]', resource('Ingress')).must_equal expectedHostName
|
||||||
|
jq('.spec.tls[0].secretName', resource('Ingress')).must_equal expectedSecretName
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user