c4768536aa69d342e1f605a636f1e084ff2303b5
[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", "pods/log", "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   backoffLimit:  {{ default 0 .Values.ric.robot.job.backoffLimit }}
107   template:
108     spec:
109       serviceAccountName: {{ $serviceAccountName }}
110       restartPolicy: {{ default "Never" .Values.ric.robot.job.restartPolicy }}
111       initContainers:
112         - name: {{ $jobName }}-generate-robot-kubeconfig
113           {{ with .Values.images.ric.robot.job.init }}
114           image: {{ if .repository }}{{- .repository -}} / {{- end -}}{{- .name -}}{{- if .tag -}} : {{- .tag -}} {{- end }}
115           imagePullPolicy: {{ default "IfNotPresent" .pullPolicy }}
116           {{- end }}
117           env:
118             - name: SVCACCT_NAME
119               value: {{ $serviceAccountName }}
120             - name: CLUSTER_NAME
121               value: {{ default "kubernetes" .Values.ric.cluster.name }}
122             - name: KUBECONFIG
123               value: /robot/etc/ric-robot-kubeconfig.conf
124             - name: K8S_API_HOST
125               value: "kubernetes.default.svc.{{ default "cluster.local" .Values.ric.cluster.domain }}"
126           command: ["/robot/bin/svcacct-to-kubeconfig.sh"]
127           volumeMounts:
128             - name: robot-etc
129               mountPath: /robot/etc
130               readOnly: false
131             {{- if .Values.ric.robot.log }}
132             - name: robot-log
133               mountPath: /robot/log
134               readOnly: false
135             {{- end }}
136             - name: robot-bin
137               mountPath: /robot/bin
138               readOnly: true
139       {{- $secrets := dict }}
140       {{- range $index, $container := .Values.images.ric.robot.job }}
141       {{- if index $container "repositoryCred" }}
142       {{- $_ := set $secrets $container.repositoryCred (dict "name" $container.repositoryCred) }}
143       {{- end }}
144       {{- end }}
145       {{- if keys $secrets }}
146       imagePullSecrets:
147       {{- values $secrets | toYaml |nindent 8 }}
148       {{- end }}
149       containers:
150         - name: {{ $jobName }}-ric-robot
151           {{ with .Values.images.ric.robot.job.run -}}
152           image: {{ if .repository }}{{- .repository -}} / {{- end -}}{{- .name -}}{{- if .tag -}} : {{- .tag -}} {{- end }}
153           imagePullPolicy: {{ default "IfNotPresent" .pullPolicy }}
154           {{- end }}
155           env:
156             - name: RICPLT_NAMESPACE
157               value: {{ $platformNamespace }}
158             - name: RICPLT_RELEASE_NAME
159               value: {{ $releaseName }}
160             - name: RICPLT_COMPONENTS
161               value: {{ keys .Values.ric.platform.components | join " " }}
162             - name: RICXAPP_NAMESPACE
163               value: {{ $xappNamespace }}
164             - name: KUBECONFIG
165               value: /robot/etc/ric-robot-kubeconfig.conf
166           command: ["robot"]
167           args:
168             - "-T"
169             {{- if not .Values.ric.robot.job.failOnTestFail }}
170             - "--NoStatusRC"
171             {{- end }}
172             {{- if .Values.ric.robot.log }}
173             - "-d"
174             - "/robot/log"
175             {{- else }}
176             - "-o"
177             - "NONE"
178             - "-l"
179             - "NONE"
180             - "-r"
181             - "NONE"
182             - "-L"
183             - "NONE"
184             {{- end }}
185             - "--console"
186             - "verbose"
187             - "-C"
188             - "off"
189             {{- if .Values.ric.robot.tags.enabled }}
190             {{- range .Values.ric.robot.tags.enabled }}
191             - "-i"
192             - "{{.}}"
193             {{- end }}
194             {{- end }}
195             {{- if .Values.ric.robot.tags.disabled }}
196             {{- range .Values.ric.robot.tags.disabled }}
197             - "-e"
198             - "{{.}}"
199             {{- end }}
200             {{- end }}
201             {{- if .Values.ric.robot.testsuites }}
202             {{- range .Values.ric.robot.testsuites }}
203             - "/robot/testsuites/{{.}}.robot"
204             {{- end }}
205             {{- else }}
206             - "/robot/testsuites"
207             {{- end }}
208           volumeMounts:
209             - name: robot-testsuites
210               mountPath: /robot/testsuites
211               readOnly: true
212             - name: robot-etc
213               mountPath: /robot/etc
214               readOnly: true
215             {{- if .Values.ric.robot.log }}
216             - name: robot-log
217               mountPath: /robot/log
218               readOnly: false
219             {{- end }}
220             # for compatability with the ric robot, we mount
221             # both properties files and interface libraries
222             # under resources/.
223 {{- range $map, $ignore := $.Files.Glob "configmap-src/*/properties/*.robot" }}
224             - name: robot-properties
225               mountPath: /robot/resources/{{ base $map }}
226               subPath: {{ base $map }}
227               readOnly: true
228 {{- end }}
229 {{- range $map, $ignore := $.Files.Glob "configmap-src/*/resources/*.robot" }}
230             - name: robot-resources
231               mountPath: /robot/resources/{{ base $map }}
232               subPath: {{ base $map }}
233               readOnly: true
234 {{- end }}
235       volumes:
236         - name: robot-etc
237           emptyDir: {}
238         - name: robot-log
239         {{- if .Values.ric.robot.log }}
240           hostPath:
241            path: {{ default "/opt/ric/robot/log"  .Values.ric.robot.log }}
242            type: DirectoryOrCreate
243         {{- end }}
244         - name: robot-bin
245           configMap:
246            name: robot-bin
247            defaultMode: 0755
248         - name: robot-testsuites
249           configMap:
250            name: robot-testsuites
251            defaultMode: 0644
252         - name: robot-properties
253           configMap:
254            name: robot-properties
255            defaultMode: 0644
256         - name: robot-resources
257           configMap:
258            name: robot-resources
259            defaultMode: 0644