0fcf772cce22bfec1e37b807be93aa655cfad749
[it/dep.git] / ric-infra / 45-Tiller / helm / xapp-tiller / templates / job-tiller-secrets.yaml
1 {{/*
2    Copyright (c) 2019 AT&T Intellectual Property.
3    Copyright (c) 2019 Nokia.
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 */}}
17 {{- if .Values.global }}
18 {{- $kubeapiServerEndpoint := .Values.global.k8sAPIHost }}
19 {{- if .Values.global.tillers }}
20 {{- $topCtx := . }}
21 {{- range keys .Values.global.tillers }}
22 {{- $key := . }}
23 {{- with index $topCtx.Values.global.tillers  . }}
24 {{- $img := .image.tillerTLSSecrets }}
25 {{- $tillerSecret := default "tiller-secret" .secret.tillerSecretName }}
26 {{- $helmSecret := default "helm-secret" .secret.helmSecretName }}
27 {{- $serviceAccountName := default "tiller" .serviceAccount }}
28 {{- $nameSpace := .nameSpace }}
29 {{- $deployNameSpace := .deployNameSpace }}
30 {{- $img := .image.tillerTLSSecrets }}
31 {{- $ctx := dict "ctx" $topCtx "key" $key }}
32 {{- if .secret.create }}
33 {{- $serviceAccountName := randAlpha 6 | lower | printf "tiller-secret-creator-%s" }}
34 ---
35 apiVersion: v1
36 kind: ServiceAccount
37 metadata:
38   name: {{ $serviceAccountName }}
39   namespace: {{ $deployNameSpace }}
40 ---
41 apiVersion: rbac.authorization.k8s.io/v1beta1
42 kind: Role
43 metadata:
44   name: {{ $serviceAccountName }}-secret-create
45   namespace: {{ $deployNameSpace }}
46 rules:
47 - apiGroups: [""]
48   resources: ["secrets"]
49   verbs: ["create", "get", "patch"]
50 ---
51 apiVersion: rbac.authorization.k8s.io/v1beta1
52 kind: RoleBinding
53 metadata:
54   name: {{ $serviceAccountName }}-secret-create
55   namespace: {{ $deployNameSpace }}
56 roleRef:
57   apiGroup: rbac.authorization.k8s.io
58   kind: Role
59   name: {{ $serviceAccountName }}-secret-create
60 subjects:
61   - kind: ServiceAccount
62     name: {{ $serviceAccountName }}
63     namespace: {{ $deployNameSpace }}
64 ---
65 apiVersion: batch/v1
66 kind: Job
67 metadata:
68   name: tiller-secret-generator
69   namespace: {{ $deployNameSpace }}
70 spec:
71   template:
72     spec:
73       serviceAccountName: {{ $serviceAccountName }}
74       restartPolicy: Never
75       imagePullSecrets:
76       {{- if $img.repositoryCred }}
77         - name: {{ $img.repositoryCred }}
78       {{- else }}
79         - name: {{ include "common.repositoryCred" $topCtx }}
80       {{- end }}
81       containers:
82         - name: tiller-secret-generator
83           image: {{ if $img.repository }}{{- $img.repository -}}/{{ else }} {{ include "common.repository" $topCtx -}}/{{- end -}}{{- $img.name -}}{{- if $img.tag -}} : {{- $img.tag -}} {{- end }}
84           imagePullPolicy: {{ default "IfNotPresent" $img.pullPolicy }}
85           env:
86             - name: ENTITIES
87               value: {{ tuple $tillerSecret $helmSecret | join " "  }}
88             - name: TILLER_KEY_NAME
89               value: {{ $tillerSecret }}.key.pem
90             - name: TILLER_CERT_NAME
91               value: {{ $tillerSecret }}.cert.pem
92             - name: HELM_KEY_NAME
93               value: {{ $helmSecret }}.key.pem
94             - name: HELM_CERT_NAME
95               value: {{ $helmSecret }}.cert.pem
96             - name: TILLER_CN
97               value: {{ default ( include "common.servicename.tiller" $ctx ) .hostname }}
98             - name: CLUSTER_SERVER
99               value: {{ default "https://kubernetes.default.svc.cluster.local/" $kubeapiServerEndpoint }}
100 {{- end }}
101 {{- end }}
102 {{- end }}
103 {{- end }}
104 {{- end }}