Enhancements for common templates
[oom.git] / kubernetes / common / common / templates / _aafconfig.tpl
1 {{/*
2 # Copyright © 2020 Amdocs, Bell Canada, highstreet technologies GmbH
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   common templates to enable aaf configs for applictaions
19
20   Parameter for aafConfig to be defined in values.yaml
21   aafConfig:   --> if a different key is used, call templates with argument (dict "aafRoot" "<yourkey>" "dot" .)
22     # additional scripts can be defined to handle certs
23     addconfig: true|false
24     fqdn: "sdnc"
25     image: onap/aaf/aaf_agent:2.1.15
26     app_ns: "org.osaaf.aaf"
27     fqi: "sdnc@sdnc.onap.org"
28     fqi_namespace: org.onap.sdnc
29     public_fqdn: "aaf.osaaf.org"
30     aafDeployFqi: "deployer@people.osaaf.org"
31     aafDeployPass: demo123456!
32     cadi_latitude: "38.0"
33     cadi_longitude: "-72.0"
34     persistence:
35       enabled: true
36       config.volumeReclaimPolicy: Delete
37       config.accessMode: ReadWriteMany
38       config.size: 40M
39       config.storageClass: "manual"
40       config.mountPath: "/dockerdata-nfs"
41       config.mountSubPath: "sdnc/aaf"
42   # secrets configuration, Note: create a secrets template
43   secrets:
44     - uid: aaf-deploy-creds
45       type: basicAuth
46       externalSecret: '{{ ternary (tpl (default "" .Values.aafConfig.aafDeployCredsExternalSecret) .) "aafIsDiabled" .Values.global.aafEnabled }}'
47       login: '{{ .Values.aafConfig.aafDeployFqi }}'
48       password: '{{ .Values.aafConfig.aafDeployPass }}'
49       passwordPolicy: required
50
51   In deployments/jobs/stateful include:
52   initContainers:
53     {{ include "common.aaf-config" . | nindent XX}}
54
55   containers:
56     volumeMounts:
57     {{- if .Values.global.aafEnabled }}
58      - mountPath: "/opt/app/osaaf"
59        name: {{ include "common.fullname" . }}-aaf-config-vol
60        {{- end }}
61   volumes:
62   {{- include "common.aaf-config-volumes" . | nindent XX}}
63
64   If persistence.enabled = true
65   Create pvc:
66   {{ include "common.aaf-config-pvc" . }}
67   Create pv
68   {{ include "common.aaf-config-pv" . }}
69
70 */}}
71 {{- define "common.aaf-config" -}}
72 {{- $dot := default . .dot -}}
73 {{- $aafRoot := default "aafConfig" .aafRoot -}}
74 {{ if .Values.global.aafEnabled }}
75 - name: {{ include "common.name" . }}-aaf-readiness
76   image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
77   imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
78   command:
79   - /root/ready.py
80   args:
81   - --container-name
82   - aaf-locate
83   - --container-name
84   - aaf-cm
85   - --container-name
86   - aaf-service
87
88   env:
89   - name: NAMESPACE
90     valueFrom:
91       fieldRef:
92         apiVersion: v1
93         fieldPath: metadata.namespace
94 - name: {{ include "common.name" . }}-aaf-config
95   image: {{ .Values.global.repository }}/{{index .Values $aafRoot "image" }}
96   imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
97   volumeMounts:
98   - mountPath: "/opt/app/osaaf"
99     name: {{ include "common.fullname" . }}-aaf-config-vol
100   {{- if (index .Values $aafRoot "addconfig") }}
101   - name: aaf-add-config
102     mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh
103     subPath: aaf-add-config.sh
104   {{- end }}
105   command:
106     - sh
107     - -c
108     - |
109       #!/usr/bin/env bash
110       /opt/app/aaf_config/bin/agent.sh
111       {{- if (index .Values $aafRoot "addconfig") }}
112       /opt/app/aaf_config/bin/aaf-add-config.sh
113       {{- end }}
114   env:
115     - name: APP_FQI
116       value: "{{ index .Values $aafRoot "fqi" }}"
117     - name: aaf_locate_url
118       value: "https://aaf-locate.{{ .Release.Namespace}}:8095"
119     - name: aaf_locator_container
120       value: "oom"
121     - name: aaf_locator_container_ns
122       value: "{{ .Release.Namespace }}"
123     - name: aaf_locator_fqdn
124       value: "{{ index .Values $aafRoot "fqdn" }}"
125     - name: aaf_locator_app_ns
126       value: "{{ index .Values $aafRoot "app_ns" }}"
127     - name: DEPLOY_FQI
128     {{- include "common.secret.envFromSecret" (dict "global" . "uid" "aaf-deploy-creds" "key" "login") | indent 6 }}
129     - name: DEPLOY_PASSWORD
130     {{- include "common.secret.envFromSecret" (dict "global" . "uid" "aaf-deploy-creds" "key" "password") | indent 6 }}
131   #Note: want to put this on Nodes, evenutally
132     - name: cadi_longitude
133       value: "{{ default "52.3" (index .Values $aafRoot "cadi_longitude") }}"
134     - name: cadi_latitude
135       value: "{{ default "13.2" (index .Values $aafRoot "cadi_latitude") }}"
136   #Hello specific.  Clients don't don't need this, unless Registering with AAF Locator
137     - name: aaf_locator_public_fqdn
138       value: "{{ (index .Values $aafRoot "public_fqdn") | default "" }}"
139 {{- end -}}
140 {{- end -}}
141
142
143 {{- define "common.aaf-config-volume-mountpath" -}}
144 {{ if .Values.global.aafEnabled }}
145 - mountPath: "/opt/app/osaaf"
146   name: {{ include "common.fullname" . }}-aaf-config-vol
147 {{- end -}}
148 {{- end -}}
149
150 {{- define "common.aaf-config-volumes" -}}
151 {{ if .Values.global.aafEnabled }}
152 {{- $dot := default . .dot -}}
153 {{- $aafRoot := default "aafConfig" .aafRoot -}}
154 - name: {{ include "common.fullname" . }}-aaf-config-vol
155   persistentVolumeClaim:
156     claimName: {{ include "common.fullname" . }}-aaf-config-pvc
157 {{- if (index .Values $aafRoot "addconfig") }}
158 - name: aaf-add-config
159   configMap:
160     name: {{ include "common.fullname" . }}-aaf-add-config
161     defaultMode: 0700
162 {{- end }}
163 {{- end -}}
164 {{- end }}
165
166 {{- define "common.aaf-config-pv" -}}
167 {{- $dot := default . .dot -}}
168 {{- $aafRoot := default "aafConfig" .aafRoot -}}
169 metadata:
170   name: {{ include "common.fullname" . }}-aaf-config-pv
171   namespace: {{ include "common.namespace" . }}
172   labels:
173     app: {{ include "common.name" . }}-aaf-config-pv
174     chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
175     release: "{{ .Release.Name }}"
176     heritage: "{{ .Release.Service }}"
177     name: {{ include "common.fullname" . }}
178 spec:
179   capacity:
180     storage: {{ index .Values $aafRoot  "persistence" "config" "size"}}
181   accessModes:
182     - {{ index .Values $aafRoot "persistence" "config" "accessMode" }}
183   persistentVolumeReclaimPolicy: {{ index .Values $aafRoot "persistence" "config" "volumeReclaimPolicy" }}
184   hostPath:
185      path: {{ index .Values $aafRoot "persistence" "config" "mountPath" }}/{{ .Release.Name }}/{{ index .Values $aafRoot "persistence" "config" "mountSubPath" }}
186 {{- if (index .Values $aafRoot "persistence" "config" "storageClass") }}
187 {{- if (eq "-" (index .Values $aafRoot "persistence" "config" "storageClass")) }}
188   storageClassName: ""
189 {{- else }}
190   storageClassName: "{{ index .Values $aafRoot "persistence" "config" "storageClass" }}"
191 {{- end }}
192 {{- end }}
193 {{- end -}}
194
195 {{- define "common.aaf-config-pvc" -}}
196 {{- $dot := default . .dot -}}
197 {{- $aafRoot := default "aafConfig" .aafRoot -}}
198 metadata:
199   name: {{ include "common.fullname" . }}-aaf-config-pvc
200   namespace: {{ include "common.namespace" . }}
201   labels:
202     app: {{ include "common.name" . }}
203     chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
204     release: "{{ .Release.Name }}"
205     heritage: "{{ .Release.Service }}"
206 {{- if (index .Values $aafRoot "persistence" "annotations") }}
207   annotations:
208 {{ toYaml (index .Values $aafRoot "persistence" "annotations" ) | indent 4 }}
209 {{- end }}
210 spec:
211   selector:
212     matchLabels:
213       app: {{ include "common.name" . }}-aaf-config-pv
214   accessModes:
215     - {{ index .Values $aafRoot "persistence" "config" "accessMode" }}
216   resources:
217     requests:
218       storage: {{ index .Values $aafRoot "persistence" "config" "size" }}
219 {{- if (index .Values $aafRoot "persistence" "config" "storageClass") }}
220 {{- if (eq "-" (index .Values $aafRoot "persistence" "config" "storageClass")) }}
221   storageClassName: ""
222 {{- else }}
223   storageClassName: "{{ index .Values $aafRoot "persistence" "config" "storageClass" }}"
224 {{- end }}
225 {{- end }}
226 {{- end -}}