2ca4ffbc43edbe6e204f1adf7c49a48d268c9b6e
[it/test.git] / ric_robot_suite / helm / nanobot / templates / job-ric-robot-run.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 {{- $platformNamespace := include "common.namespace.platform" . }}
18 {{- $xappNamespace := include "common.namespace.xapp" .  }}
19 {{- $releaseName := default "ric-full" .Values.ric.platform.releaseName }}
20 {{- $jobName :=  printf "%s-%s" .Release.Name $releaseName }}
21 {{- $acctName := randAlpha 6 | lower | printf "%s-%s" $jobName }}
22 {{- $serviceAccountName := default $acctName .Values.ric.robot.job.serviceAccount.name }}
23 {{- if .Values.ric.robot.job.serviceAccount.create }}
24 ---
25 apiVersion: v1
26 kind: ServiceAccount
27 metadata:
28   name: {{ $serviceAccountName }}
29   namespace: {{ .Release.Namespace }}
30 ---
31 apiVersion: rbac.authorization.k8s.io/v1beta1
32 kind: Role
33 metadata:
34   name: {{ $serviceAccountName }}-{{ $releaseName }}-ricplatform-access
35   namespace: {{ $platformNamespace }}
36 rules:
37 - apiGroups: [""]
38   resources: ["pods", "services"]
39   verbs: ["get", "list"]
40 - apiGroups: ["apps"]
41   resources: ["daemonsets", "replicasets", "statefulsets"]
42   verbs: ["get", "list"]
43 - apiGroups: ["extensions"]
44   resources: ["daemonsets", "replicasets"]
45   verbs: ["get", "list"]
46 - apiGroups: ["apps"]
47   resources: ["deployments"]
48   verbs: ["get", "list", "patch"]
49 - apiGroups: ["extensions"]
50   resources: ["deployments"]
51   verbs: ["get", "list", "patch"]
52 ---
53 apiVersion: rbac.authorization.k8s.io/v1beta1
54 kind: RoleBinding
55 metadata:
56   name: {{ $serviceAccountName }}-{{ $releaseName }}-ricplatform-access
57   namespace: {{ $platformNamespace }}
58 roleRef:
59   apiGroup: rbac.authorization.k8s.io
60   kind: Role
61   name: {{ $serviceAccountName }}-{{ $releaseName }}-ricplatform-access
62 subjects:
63   - kind: ServiceAccount
64     name: {{ $serviceAccountName }}
65     namespace: {{ .Release.Namespace }}
66 {{- if ne $xappNamespace $platformNamespace }}
67 ---
68 apiVersion: rbac.authorization.k8s.io/v1beta1
69 kind: Role
70 metadata:
71   name: {{ $serviceAccountName }}-{{ $releaseName }}-xapp-access
72   namespace: {{ $xappNamespace }}
73 rules:
74 - apiGroups: [""]
75   resources: ["pods", "services"]
76   verbs: ["get", "list"]
77 - apiGroups: ["apps"]
78   resources: ["deployments", "daemonsets", "replicasets", "statefulsets"]
79   verbs: ["get", "list"]
80 - apiGroups: ["extensions"]
81   resources: ["deployments", "daemonsets", "replicasets"]
82   verbs: ["get", "list"]
83 ---
84 apiVersion: rbac.authorization.k8s.io/v1beta1
85 kind: RoleBinding
86 metadata:
87   name: {{ $serviceAccountName }}-{{ $releaseName }}-xapp-access
88   namespace: {{ $xappNamespace }}
89 roleRef:
90   apiGroup: rbac.authorization.k8s.io
91   kind: Role
92   name: {{ $serviceAccountName }}-{{ $releaseName }}-xapp-access
93 subjects:
94   - kind: ServiceAccount
95     name: {{ $serviceAccountName }}
96     namespace: {{ .Release.Namespace }}
97 {{- end }}
98 {{- end }}
99 ---
100 apiVersion: batch/v1
101 kind: Job
102 metadata:
103   name: {{ $jobName }}-ric-robot-run
104   namespace: {{ .Release.Namespace }}
105 spec:
106   template:
107     spec:
108       serviceAccountName: {{ $serviceAccountName }}
109       restartPolicy: Never
110       initContainers:
111         - name: {{ $jobName }}-generate-robot-kubeconfig
112           {{ with .Values.images.ric.robot.job.init }}
113           image: {{ if .repository }}{{- .repository -}} / {{- end -}}{{- .name -}}{{- if .tag -}} : {{- .tag -}} {{- end }}
114           imagePullPolicy: {{ default "IfNotPresent" .pullPolicy }}
115           {{- end }}
116           env:
117             - name: SVCACCT_NAME
118               value: {{ $serviceAccountName }}
119             - name: CLUSTER_NAME
120               value: {{ default "kubernetes" .Values.ric.cluster.name }}
121             - name: KUBECONFIG
122               value: /robot/etc/ric-robot-kubeconfig.conf
123             - name: K8S_API_HOST
124               value: "kubernetes.default.svc.{{ default "cluster.local" .Values.ric.cluster.domain }}"
125           command: ["/robot/bin/svcacct-to-kubeconfig.sh"]
126           volumeMounts:
127             - name: robot-etc
128               mountPath: /robot/etc
129               readOnly: false
130             {{- if .Values.ric.robot.log }}
131             - name: robot-log
132               mountPath: /robot/log
133               readOnly: false
134             {{- end }}
135             - name: robot-bin
136               mountPath: /robot/bin
137               readOnly: true
138       {{- $secrets := dict }}
139       {{- range $index, $container := .Values.images.ric.robot.job }}
140       {{- if index $container "repositoryCred" }}
141       {{- $_ := set $secrets $container.repositoryCred (dict "name" $container.repositoryCred) }}
142       {{- end }}
143       {{- end }}
144       {{- if keys $secrets }}
145       imagePullSecrets:
146       {{- values $secrets | toYaml |nindent 8 }}
147       {{- end }}
148       containers:
149         - name: {{ $jobName }}-ric-robot
150           {{ with .Values.images.ric.robot.job.run -}}
151           image: {{ if .repository }}{{- .repository -}} / {{- end -}}{{- .name -}}{{- if .tag -}} : {{- .tag -}} {{- end }}
152           imagePullPolicy: {{ default "IfNotPresent" .pullPolicy }}
153           {{- end }}
154           env:
155             - name: RICPLT_NAMESPACE
156               value: {{ $platformNamespace }}
157             - name: RICPLT_RELEASE_NAME
158               value: {{ $releaseName }}
159             - name: RICPLT_COMPONENTS
160               value: {{ keys .Values.ric.platform.components | join " " }}
161             - name: RICXAPP_NAMESPACE
162               value: {{ $xappNamespace }}
163             - name: KUBECONFIG
164               value: /robot/etc/ric-robot-kubeconfig.conf
165           command: ["robot"]
166           args:
167             - "-T"
168             {{- if not .Values.ric.robot.job.failOnTestFail }}
169             - "--NoStatusRC"
170             {{- end }}
171             {{- if .Values.ric.robot.log }}
172             - "-d"
173             - "/robot/log"
174             {{- else }}
175             - "-o"
176             - "NONE"
177             - "-l"
178             - "NONE"
179             - "-r"
180             - "NONE"
181             - "-L"
182             - "NONE"
183             {{- end }}
184             - "--console"
185             - "verbose"
186             - "-C"
187             - "off"
188             {{- if .Values.ric.robot.tags.enabled }}
189             {{- range .Values.ric.robot.tags.enabled }}
190             - "-i"
191             - "{{.}}"
192             {{- end }}
193             {{- end }}
194             {{- if .Values.ric.robot.tags.disabled }}
195             {{- range .Values.ric.robot.tags.disabled }}
196             - "-e"
197             - "{{.}}"
198             {{- end }}
199             {{- end }}
200             {{- if .Values.ric.robot.testsuites }}
201             {{- range .Values.ric.robot.testsuites }}
202             - "/robot/testsuites/{{.}}.robot"
203             {{- end }}
204             {{- else }}
205             - "/robot/testsuites"
206             {{- end }}
207           volumeMounts:
208             - name: robot-testsuites
209               mountPath: /robot/testsuites
210               readOnly: true
211             - name: robot-etc
212               mountPath: /robot/etc
213               readOnly: true
214             {{- if .Values.ric.robot.log }}
215             - name: robot-log
216               mountPath: /robot/log
217               readOnly: false
218             {{- end }}
219             # for compatability with the ric robot, we mount
220             # both properties files and interface libraries
221             # under resources/.
222 {{- range $map, $ignore := $.Files.Glob "configmap-src/*/properties/*.robot" }}
223             - name: robot-properties
224               mountPath: /robot/resources/{{ base $map }}
225               subPath: {{ base $map }}
226               readOnly: true
227 {{- end }}
228 {{- range $map, $ignore := $.Files.Glob "configmap-src/*/resources/*.robot" }}
229             - name: robot-resources
230               mountPath: /robot/resources/{{ base $map }}
231               subPath: {{ base $map }}
232               readOnly: true
233 {{- end }}
234       volumes:
235         - name: robot-etc
236           emptyDir: {}
237         - name: robot-log
238         {{- if .Values.ric.robot.log }}
239           hostPath:
240            path: {{ default "/opt/ric/robot/log"  .Values.ric.robot.log }}
241            type: DirectoryOrCreate
242         {{- end }}
243         - name: robot-bin
244           configMap:
245            name: robot-bin
246            defaultMode: 0755
247         - name: robot-testsuites
248           configMap:
249            name: robot-testsuites
250            defaultMode: 0644
251         - name: robot-properties
252           configMap:
253            name: robot-properties
254            defaultMode: 0644
255         - name: robot-resources
256           configMap:
257            name: robot-resources
258            defaultMode: 0644