Skip to content

Commit 39cfdce

Browse files
Merge pull request #13 from codefresh-io/CR-14535
+semver: patch upd tunnels-ingress template; added exsitingSecret option; added tls-secret templates
2 parents 16d3998 + c88c002 commit 39cfdce

File tree

9 files changed

+115
-15
lines changed

9 files changed

+115
-15
lines changed

codefresh-tunnel-server/templates/_helpers.tpl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,45 @@ Ingress url for tunnels
127127
{{- end -}}
128128
{{- end -}}
129129

130+
131+
{{/*
132+
Return true if a TLS secret object should be created for tunnels ingress
133+
*/}}
134+
{{- define "codefresh-tunnel-server.tunnels.createTlsSecret" -}}
135+
{{- if and .Values.tunnels.ingress.tls.enabled (not .Values.tunnels.ingress.tls.existingSecret) }}
136+
{{- true -}}
137+
{{- end -}}
138+
{{- end -}}
139+
140+
{{/*
141+
Return true if a TLS secret object should be created for tunnel server
142+
*/}}
143+
{{- define "codefresh-tunnel-server.createTlsSecret" -}}
144+
{{- if and .Values.ingress.tls.enabled (not .Values.ingress.tls.existingSecret) }}
145+
{{- true -}}
146+
{{- end -}}
147+
{{- end -}}
148+
149+
{{/*
150+
Return the secret containing TLS certificates for tunnels ingress
151+
*/}}
152+
{{- define "codefresh-tunnel-server.tunnels.tlsSecretName" -}}
153+
{{- $secretName := .Values.tunnels.ingress.tls.existingSecret -}}
154+
{{- if $secretName -}}
155+
{{- printf "%s" (tpl $secretName $) -}}
156+
{{- else -}}
157+
{{- printf "%s-tunnels-cert" (include "codefresh-tunnel-server.name" .) -}}
158+
{{- end -}}
159+
{{- end -}}
160+
161+
{{/*
162+
Return the secret containing TLS certificates for tunnel server
163+
*/}}
164+
{{- define "codefresh-tunnel-server.tlsSecretName" -}}
165+
{{- $secretName := .Values.ingress.tls.existingSecret -}}
166+
{{- if $secretName -}}
167+
{{- printf "%s" (tpl $secretName $) -}}
168+
{{- else -}}
169+
{{- printf "%s-cert" (include "codefresh-tunnel-server.name" .) -}}
170+
{{- end -}}
171+
{{- end -}}

codefresh-tunnel-server/templates/tunnel-server-ingress.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ spec:
2020
tls:
2121
- hosts:
2222
- {{ .Values.ingress.host }}
23-
{{- if .Values.ingress.tls.secretName }}
24-
secretName: {{ .Values.ingress.tls.secretName }}
25-
{{- else }}
26-
{{ fail "TLS for ingress is enabled but no secretName provided"}}
27-
{{- end }}
23+
secretName: {{ include "codefresh-tunnel-server.tlsSecretName" . }}
2824
{{- end }}
2925
{{- end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if (include "codefresh-tunnel-server.createTlsSecret" .) }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "codefresh-tunnel-server.tlsSecretName" . }}
6+
labels:
7+
{{- include "codefresh-tunnel-server.labels" . | nindent 4 }}
8+
type: kubernetes.io/tls
9+
data:
10+
{{- $tls := buildCustomCert (required "A valid .Values.ingress.tls.cert is required!" .Values.ingress.tls.cert) (required "A valid .Values.ingress.tls.key is required!" .Values.ingress.tls.key) }}
11+
tls.crt: {{ b64enc $tls.Cert }}
12+
tls.key: {{ b64enc $tls.Key }}
13+
{{- end }}

codefresh-tunnel-server/templates/tunnels-ingress.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ spec:
1919
{{- if .Values.tunnels.ingress.tls.enabled }}
2020
tls:
2121
- hosts:
22-
- {{ .Values.tunnels.ingress.host }}
23-
{{- if .Values.tunnels.ingress.tls.secretName }}
24-
secretName: {{ .Values.tunnels.ingress.tls.secretName }}
25-
{{- else }}
26-
{{ fail "TLS for ingress is enabled but no secretName provided"}}
27-
{{- end }}
22+
- {{ include "codefresh-tunnel-server.tunnels-ingress-host" . }}
23+
secretName: {{ include "codefresh-tunnel-server.tunnels.tlsSecretName" . }}
2824
{{- end }}
2925
{{- end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if (include "codefresh-tunnel-server.tunnels.createTlsSecret" .) }}
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "codefresh-tunnel-server.tunnels.tlsSecretName" . }}
6+
labels:
7+
{{- include "codefresh-tunnel-server.labels" . | nindent 4 }}
8+
type: kubernetes.io/tls
9+
data:
10+
{{- $tls := buildCustomCert (required "A valid .Values.tunnels.ingress.tls.cert is required!" .Values.tunnels.ingress.tls.cert) (required "A valid .Values.tunnels.ingress.tls.key is required!" .Values.tunnels.ingress.tls.key) }}
11+
tls.crt: {{ b64enc $tls.Cert }}
12+
tls.key: {{ b64enc $tls.Key }}
13+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
suite: Test tunnels ingress tls secret
2+
templates:
3+
- tunnel-server-ingress.yaml
4+
- tunnel-server-tls-secret.yaml
5+
tests:
6+
- it: Should equal to existingSecret when existingSecret is set
7+
template: tunnel-server-ingress.yaml
8+
set:
9+
ingress.enabled: true
10+
host: register-tunnels.example.com
11+
ingress.tls.enabled: true
12+
ingress.tls.existingSecret: my-existing-secret
13+
asserts:
14+
- equal:
15+
path: spec.tls[0].secretName
16+
value: "my-existing-secret"

codefresh-tunnel-server/tests/tunnels_ingress_test.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,3 @@ tests:
4545
asserts:
4646
- failedTemplate:
4747
errorMessage: "subdomainHost or host must be provided for tunnels ingress"
48-
49-
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
suite: Test tunnels ingress tls secret
2+
templates:
3+
- tunnels-ingress.yaml
4+
- tunnels-tls-secret.yaml
5+
tests:
6+
- it: Should equal to existingSecret when existingSecret is set
7+
template: tunnels-ingress.yaml
8+
set:
9+
tunnels.ingress.enabled: true
10+
tunnels.subdomainHost: tunnels.example.com
11+
tunnels.ingress.tls.enabled: true
12+
tunnels.ingress.tls.existingSecret: my-existing-secret
13+
asserts:
14+
- equal:
15+
path: spec.tls[0].secretName
16+
value: "my-existing-secret"

codefresh-tunnel-server/values.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ tunnels:
3030
# kubernetes.io/tls-acme: "true"
3131
tls:
3232
enabled: false
33-
secretName:
33+
# Existing secret with TLS certificate
34+
existingSecret:
35+
# Custom certificate (base64 encoded)
36+
cert: ""
37+
# Custom private key (base64 encoded)
38+
key: ""
3439

3540
# The serive of the tunnel server
3641
service:
@@ -46,7 +51,12 @@ ingress:
4651
# kubernetes.io/tls-acme: "true"
4752
tls:
4853
enabled: false
49-
secretName:
54+
# Existing secret with TLS certificate
55+
existingSecret:
56+
# Custom certificate (base64 encoded)
57+
cert: ""
58+
# Custom private key (base64 encoded)
59+
key: ""
5060

5161
serviceAccount:
5262
create: true

0 commit comments

Comments
 (0)