Merge "[UUI] Service Mesh Compliance for UUI"
[oom.git] / kubernetes / common / common / templates / _pod.tpl
1 {{/*
2 # Copyright © 2019 Orange
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16
17 {{/*
18   Generate the container port list.
19   Will use first ".Values.service.ports" list.
20   Will append ports from ".Values.service.headlessPorts" only if port number is
21   not already in port list.
22   Will add tls port AND plain port if both_tls_and_plain is set to true
23 */}}
24 {{- define "common.containerPorts" -}}
25 {{-   $ports := default (list) .Values.service.ports }}
26 {{-   $portsNumber := list }}
27 {{-   $both_tls_and_plain:= default false .Values.service.both_tls_and_plain }}
28 {{-   range $index, $port := $ports }}
29 {{-     $portsNumber = append $portsNumber $port.port }}
30 {{-   end }}
31 {{-   range $index, $port := .Values.service.headlessPorts }}
32 {{-     if not (has $port.port $portsNumber) }}
33 {{-       $ports = append $ports $port }}
34 {{-     end }}
35 {{-   end }}
36 {{- $global := . }}
37 {{-   range $index, $port := $ports }}
38 {{-     if (include "common.needTLS" $global) }}
39 - containerPort: {{ default $port.port $port.internal_port }}
40 {{-     else }}
41 - containerPort: {{ default (default $port.port $port.internal_port) (default $port.plain_port $port.internal_plain_port) }}
42 {{-     end }}
43   name: {{ $port.name }}
44 {{-     if (and $port.plain_port (and (include "common.needTLS" $global) $both_tls_and_plain))  }}
45 - containerPort: {{ default $port.plain_port $port.internal_plain_port }}
46   name: {{ $port.name }}-plain
47 {{-     end }}
48 {{-   end }}
49 {{- end -}}
50
51 {{/*
52    Generate securityContext for pod
53 */}}
54 {{- define "common.podSecurityContext" -}}
55 securityContext:
56   runAsUser: {{ .Values.securityContext.user_id }}
57   runAsGroup: {{ .Values.securityContext.group_id }}
58   fsGroup: {{ .Values.securityContext.group_id }}
59 {{- end }}
60
61 {{/*
62    Generate securityContext for container
63 */}}
64 {{- define "common.containerSecurityContext" -}}
65 securityContext:
66   readOnlyRootFilesystem: true
67   privileged: false
68   allowPrivilegeEscalation: false
69 {{- end }}