forked from cloudfoundry/stratos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__helpers.tpl
168 lines (152 loc) · 4.97 KB
/
__helpers.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{{/* vim: set filetype=mustache: */}}
{{/*
Image pull secret
*/}}
{{- define "imagePullSecret" }}
{{- printf "{\"%s\":{\"username\": \"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\": \"%s\"}}" .Values.kube.registry.hostname .Values.kube.registry.username .Values.kube.registry.password .Values.kube.registry.email (printf "%s:%s" .Values.kube.registry.username .Values.kube.registry.password | b64enc) | b64enc }}
{{- end }}
{{/*
Determine external IPs:
This will do the following:
1. Check for Legacy SCF Config format
2. Check for Console specific External IP
3. Check for New SCF Config format
4. Check for new Console External IPS
*/}}
{{- define "service.externalIPs" -}}
{{- if .Values.kube.external_ip }}
externalIPs:
{{- printf "\n - %s" .Values.kube.external_ip | indent 3 -}}
{{- printf "\n" -}}
{{- else if .Values.console.externalIP }}
externalIPs:
{{- printf "\n - %s" .Values.console.externalIP | indent 3 -}}
{{- printf "\n" -}}
{{- else if .Values.kube.external_ips }}
externalIPs:
{{- range .Values.kube.external_ips -}}
{{- printf "\n- %s" . | indent 4 -}}
{{- end -}}
{{- printf "\n" -}}
{{- else if .Values.console.service -}}
{{- if .Values.console.service.externalIPs }}
externalIPs:
{{- range .Values.console.service.externalIPs -}}
{{ printf "\n- %s" . | indent 4 }}
{{- end -}}
{{- printf "\n" -}}
{{- end -}}
{{- end -}}
{{ end }}
{{/*
Get SCF UAA Endpoint
*/}}
{{- define "scfUaaEndpoint" -}}
{{- $uaa_zone := default "scf" .Values.env.UAA_ZONE -}}
{{- if and .Values.env.DOMAIN (not .Values.env.UAA_HOST) -}}
{{- if .Values.env.UAA_ZONE -}}
{{- printf "https://%s.uaa.%s:%v" .Values.env.UAA_ZONE .Values.env.DOMAIN .Values.env.UAA_PORT -}}
{{- else -}}
{{- printf "https://uaa.%s:%v" .Values.env.DOMAIN .Values.env.UAA_PORT -}}
{{- end -}}
{{- else if .Values.env.UAA_HOST -}}
{{- if .Values.env.UAA_ZONE -}}
{{- printf "https://%s.%s:%v" .Values.env.UAA_ZONE .Values.env.UAA_HOST .Values.env.UAA_PORT -}}
{{- else -}}
{{- printf "https://%s:%v" .Values.env.UAA_HOST .Values.env.UAA_PORT -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Service type:
*/}}
{{- define "service.serviceType" -}}
{{- if or .Values.useLb .Values.services.loadbalanced -}}
LoadBalancer
{{- else -}}
{{- if .Values.console.service -}}
{{- default "ClusterIP" .Values.console.service.type -}}
{{- else -}}
ClusterIP
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Service port:
*/}}
{{- define "service.servicePort" -}}
{{- if and .Values.kube.external_ips .Values.kube.external_console_https_port -}}
{{ printf "%v" .Values.kube.external_console_https_port }}
{{- else -}}
{{- if .Values.console.service -}}
{{ default 443 .Values.console.service.servicePort}}
{{- else -}}
443
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Expand the name of the chart.
*/}}
{{- define "console.certName" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Generate self-signed certificate
*/}}
{{- define "console.generateCertificate" -}}
{{- $altNames := list ( printf "%s.%s" (include "console.certName" .) .Release.Namespace ) ( printf "%s.%s.svc" (include "console.certName" .) .Release.Namespace ) -}}
{{- $ca := genCA "stratos-ca" 365 -}}
{{- $cert := genSignedCert ( include "console.certName" . ) nil $altNames 365 $ca -}}
tls.crt: {{ $cert.Cert | b64enc }}
tls.key: {{ $cert.Key | b64enc }}
{{- end -}}
{{/*
Generate self-signed certificate for ingress if needed
*/}}
{{- define "console.generateIngressCertificate" -}}
{{- $altNames := list (printf "%s" .Values.console.service.ingress.host) (printf "%s.%s" (include "console.certName" .) .Release.Namespace ) ( printf "%s.%s.svc" (include "console.certName" .) .Release.Namespace ) -}}
{{- $ca := genCA "stratos-ca" 365 -}}
{{- $cert := genSignedCert ( include "console.certName" . ) nil $altNames 365 $ca -}}
{{- if .Values.console.service.ingress.tls.crt }}
tls.crt: {{ .Values.console.service.ingress.tls.crt | b64enc | quote }}
{{- else }}
tls.crt: {{ $cert.Cert | b64enc | quote }}
{{- end -}}
{{- if .Values.console.service.ingress.tls.key }}
tls.key: {{ .Values.console.service.ingress.tls.key | b64enc | quote }}
{{- else }}
tls.key: {{ $cert.Key | b64enc | quote }}
{{- end -}}
{{- end -}}
{{/*
Ingress Host from .Values.console.service
*/}}
{{- define "ingress.host.value" -}}
{{- if .Values.console.service -}}
{{- if .Values.console.service.ingress -}}
{{- if .Values.console.service.ingress.host -}}
{{ .Values.console.service.ingress.host }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Ingress Host:
*/}}
{{- define "ingress.host" -}}
{{ $host := (include "ingress.host.value" .) }}
{{- if $host -}}
{{ $host | quote }}
{{- else if .Values.env.DOMAIN -}}
{{ print "console." .Values.env.DOMAIN }}
{{- end -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}