[DCAEGEN2-SVCS] Support config update via configMap
[oom.git] / kubernetes / common / common / templates / _dmaapProvisioning.tpl
1 {{/*
2 ################################################################################
3 #   Copyright (C) 2021 Nordix Foundation.                                      #
4 #   Copyright (c) 2022 J. F. Lucas.  All rights reserved.                      #
5 #                                                                              #
6 #   Licensed under the Apache License, Version 2.0 (the "License");            #
7 #   you may not use this file except in compliance with the License.           #
8 #   You may obtain a copy of the License at                                    #
9 #                                                                              #
10 #       http://www.apache.org/licenses/LICENSE-2.0                             #
11 #                                                                              #
12 #   Unless required by applicable law or agreed to in writing, software        #
13 #   distributed under the License is distributed on an "AS IS" BASIS,          #
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15 #   See the License for the specific language governing permissions and        #
16 #   limitations under the License.                                             #
17 ################################################################################
18 */}}
19
20 {{/*
21   This template generates a Kubernetes init containers common template to enable applications to provision
22   DMaaP feeds (on Data Router), with associated authorization.
23   DMaap Bus Controller endpoints are used to provision:
24
25   - Feed on DR, with associated user authentication.
26
27   common.dmaap.provisioning.initContainer:
28   This template make use of Dmaap Bus Controller docker image to create resources on Dmaap Data Router
29   microservice, with the help of dbc-client.sh script it makes use of Bus Controller API to create Feeds.
30   If the resource creation is successful via script response is logged back at particular location with
31   appropriate naming convention.
32
33   More details can be found at :
34   (https://wiki.onap.org/pages/viewpage.action?pageId=103417564)
35
36   The template directly references data in .Values, and indirectly (through its
37   use of templates from the ONAP "common" collection) references data in .Release.
38
39   Parameter for _dmaapProvisioning to be defined in values.yaml
40   # DataRouter Feed Configuration
41   drFeedConfig:
42     - feedName: bulk_pm_feed
43       owner: dcaecm
44       feedVersion: 0.0
45       asprClassification: unclassified
46       feedDescription: DFC Feed Creation
47
48   # DataRouter Publisher Configuration
49   drPubConfig:
50     - feedName: bulk_pm_feed
51       dcaeLocationName: loc00
52
53   # DataRouter Subscriber Configuration
54   drSubConfig:
55     - feedName: bulk_pm_feed
56       decompress: True
57       dcaeLocationName: loc00
58       privilegedSubscriber: True
59       deliveryURL: https://dcae-pm-mapper:8443/delivery
60
61   # ConfigMap Configuration for DR Feed, Dr_Publisher, Dr_Subscriber
62   volumes:
63     - name: feeds-config
64       path: /opt/app/config/feeds
65     - name: drpub-config
66       path: /opt/app/config/dr_pubs
67     - name: drsub-config
68       path: /opt/app/config/dr_subs
69
70   In deployments/jobs/stateful include:
71   initContainers:
72   {{- include "common.dmaap.provisioning.initContainer" . | nindent XX }}
73   volumes:
74   {{- include "common.dmaap.provisioning._volumes" . | nindent XX -}}
75 */}}
76
77 {{- define "common.dmaap.provisioning._volumeMounts" -}}
78 {{- $dot := default . .dot -}}
79 - mountPath: /opt/app/config/cache
80   name: dbc-response-cache
81 {{- range $name, $volume := $dot.Values.volumes }}
82 - name: {{ $volume.name }}
83   mountPath: {{ $volume.path }}
84 {{- end }}
85 {{- end -}}
86
87 {{- define "common.dmaap.provisioning._volumes" -}}
88 {{- $dot := default . .dot -}}
89 - name: dbc-response-cache
90   emptyDir: {}
91 {{- range $name, $volume := $dot.Values.volumes }}
92 - name: {{ $volume.name }}
93   configMap:
94     defaultMode: 420
95     name: {{ include "common.fullname" $dot }}-{{ printf "%s" $volume.name }}
96 {{- end }}
97 {{- end -}}
98
99 {{- define "common.dmaap.provisioning.initContainer" -}}
100 {{- $dot := default . .dot -}}
101 {{- $drFeedConfig := default $dot.Values.drFeedConfig .drFeedConfig -}}
102 {{- if $drFeedConfig -}}
103 - name: {{ include "common.name" $dot }}-init-dmaap-provisioning
104   image: {{ include "repositoryGenerator.image.dbcClient" $dot }}
105   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
106   env:
107   - name: RESP_CACHE
108     value: /opt/app/config/cache
109   - name: REQUESTID
110     value: "{{ include "common.name" $dot }}-dmaap-provisioning"
111   {{- range $cred := $dot.Values.credentials }}
112   - name: {{ $cred.name }}
113     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
114   {{- end }}
115   volumeMounts:
116   {{- include "common.dmaap.provisioning._volumeMounts" $dot | trim | nindent 2 }}
117   resources: {{ include "common.resources" $dot | nindent 1 }}
118 - name: {{ include "common.name" $dot }}-init-merge-config
119   image: {{ include "repositoryGenerator.image.envsubst" $dot }}
120   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
121   command:
122   - /bin/sh
123   args:
124   - -c
125   - |
126     set -uex -o pipefail
127     if [ -d /opt/app/config/cache ]; then
128       cd /opt/app/config/cache
129       for file in $(ls feed*); do
130         NUM=$(echo "$file" | sed 's/feedConfig-\([0-9]\+\)-resp.json/\1/')
131         export DR_LOG_URL_"$NUM"="$(grep -o '"logURL":"[^"]*' "$file" | grep -w "feedlog" | cut -d '"' -f4)"
132         export DR_FILES_PUBLISHER_URL_"$NUM"="$(grep -o '"publishURL":"[^"]*' "$file" | cut -d '"' -f4)"
133       done
134       for file in $(ls drpub*); do
135         NUM=$(echo "$file" | sed 's/drpubConfig-\([0-9]\+\)-resp.json/\1/')
136         export DR_FILES_PUBLISHER_ID_"$NUM"="$(grep -o '"pubId":"[^"]*' "$file" | cut -d '"' -f4)"
137       done
138       for file in $(ls drsub*); do
139         NUM=$(echo "$file" | sed 's/drsubConfig-\([0-9]\+\)-resp.json/\1/')
140         export DR_FILES_SUBSCRIBER_ID_"$NUM"="$(grep -o '"subId":"[^"]*' "$file" | cut -d '"' -f4)"
141       done
142       for file in $(ls topics*); do
143         NUM=$(echo "$file" | sed 's/topicsConfig-\([0-9]\+\)-resp.json/\1/')
144         export MR_FILES_PUBLISHER_CLIENT_ID_"$NUM"="$(grep -o '"mrClientId":"[^"]*' "$file" | cut -d '"' -f4)"
145       done
146     else
147       echo "No Response logged for Dmaap BusController Http POST Request..!"
148     fi
149     cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
150   env:
151   {{- range $cred := $dot.Values.credentials }}
152   - name: {{ $cred.name }}
153     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
154   {{- end }}
155   volumeMounts:
156   - mountPath: /opt/app/config/cache
157     name: dbc-response-cache
158   - mountPath: /config-input
159     name: app-config-input
160   - mountPath: /config
161     name: app-config
162   resources:
163     limits:
164       cpu: 200m
165       memory: 250Mi
166     requests:
167       cpu: 100m
168       memory: 200Mi
169 {{- end -}}
170 {{- end -}}