eefd00d7bf411223abfc1e9624a81746b29a765f
[oom.git] / kubernetes / common / common / templates / _dmaapProvisioning.tpl
1 {{/*
2 ################################################################################
3 #   Copyright (C) 2021 Nordix Foundation.                                      #
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 */}}
18
19 {{/*
20   This template generates a Kubernetes init containers common template to enable applications to provision
21   DMaaP topics (on Message Router) and feeds (on Data Router), with associated authorization (on AAF).
22   DMaap Bus Controller endpoints are used to provision:
23   - Authorized topic on MR, and to create and grant permission for publishers and subscribers.
24   - Feed on DR, with associated user authentication.
25
26   common.dmaap.provisioning.initContainer:
27   This template make use of Dmaap Bus Controller docker image to create resources on Dmaap Data Router
28   microservice, with the help of dbc-client.sh script it makes use of Bus Controller API to create Feed, Topics.
29   If the resource creation is successful via script response is logged back at particular location with
30   appropriate naming convention.
31
32   More details can be found at :
33   (https://wiki.onap.org/pages/viewpage.action?pageId=103417564)
34
35   The template directly references data in .Values, and indirectly (through its
36   use of templates from the ONAP "common" collection) references data in .Release.
37
38   Parameter for _dmaapProvisioning to be defined in values.yaml
39   # DataRouter Feed Configuration
40   drFeedConfig:
41     - feedName: bulk_pm_feed
42       owner: dcaecm
43       feedVersion: 0.0
44       asprClassification: unclassified
45       feedDescription: DFC Feed Creation
46
47   # DataRouter Publisher Configuration
48   drPubConfig:
49     - feedName: bulk_pm_feed
50       dcaeLocationName: loc00
51
52   # DataRouter Subscriber Configuration
53   drSubConfig:
54     - feedName: bulk_pm_feed
55       decompress: True
56       dcaeLocationName: loc00
57       privilegedSubscriber: True
58       deliveryURL: https://dcae-pm-mapper:8443/delivery
59
60   # MessageRouter Topic, Publisher Configuration
61   mrTopicsConfig:
62     - topicName: PERFORMANCE_MEASUREMENTS
63       topicDescription: Description about Topic
64       owner: dcaecm
65       tnxEnabled: false
66       clients:
67         - dcaeLocationName: san-francisco
68           clientRole: org.onap.dcae.pmPublisher
69           action:
70             - pub
71             - view
72
73   # ConfigMap Configuration for DR Feed, Dr_Publisher, Dr_Subscriber, MR Topics
74   volumes:
75     - name: feeds-config
76       path: /opt/app/config/feeds
77     - name: drpub-config
78       path: /opt/app/config/dr_pubs
79     - name: drsub-config
80       path: /opt/app/config/dr_subs
81     - name: topics-config
82       path: /opt/app/config/topics
83
84   In deployments/jobs/stateful include:
85   initContainers:
86   {{- include "common.dmaap.provisioning.initContainer" . | nindent XX }}
87   volumes:
88   {{- include "common.dmaap.provisioning._volumes" . | nindent XX -}}
89 */}}
90
91 {{- define "common.dmaap.provisioning._volumeMounts" -}}
92 {{- $dot := default . .dot -}}
93 - mountPath: /opt/app/config/cache
94   name: dbc-response-cache
95 {{- range $name, $volume := $dot.Values.volumes }}
96 - name: {{ $volume.name }}
97   mountPath: {{ $volume.path }}
98 {{- end }}
99 {{- end -}}
100
101 {{- define "common.dmaap.provisioning._volumes" -}}
102 {{- $dot := default . .dot -}}
103 - name: dbc-response-cache
104   emptyDir: {}
105 {{- range $name, $volume := $dot.Values.volumes }}
106 - name: {{ $volume.name }}
107   configMap:
108     defaultMode: 420
109     name: {{ include "common.fullname" $dot }}-{{ printf "%s" $volume.name }}
110 {{- end }}
111 {{- end -}}
112
113 {{- define "common.dmaap.provisioning.initContainer" -}}
114 {{- $dot := default . .dot -}}
115 {{- $drFeedConfig := default $dot.Values.drFeedConfig .drFeedConfig -}}
116 {{- $mrTopicsConfig := default $dot.Values.mrTopicsConfig .mrTopicsConfig -}}
117 {{- if or $drFeedConfig $mrTopicsConfig -}}
118 - name: {{ include "common.name" $dot }}-init-dmaap-provisioning
119   image: {{ include "repositoryGenerator.image.dbcClient" $dot }}
120   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
121   env:
122   - name: RESP_CACHE
123     value: /opt/app/config/cache
124   - name: REQUESTID
125     value: "{{ include "common.name" $dot }}-dmaap-provisioning"
126   {{- range $cred := $dot.Values.credentials }}
127   - name: {{ $cred.name }}
128     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
129   {{- end }}
130   volumeMounts:
131   {{- include "common.dmaap.provisioning._volumeMounts" $dot | trim | nindent 2 }}
132   resources: {{ include "common.resources" $dot | nindent 1 }}
133 - name: {{ include "common.name" $dot }}-init-merge-config
134   image: {{ include "repositoryGenerator.image.envsubst" $dot }}
135   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
136   command:
137   - /bin/sh
138   args:
139   - -c
140   - |
141     set -uex -o pipefail
142     if [ -d /opt/app/config/cache ]; then
143       cd /opt/app/config/cache
144       for file in $(ls feed*); do
145         NUM=$(echo "$file" | sed 's/feedConfig-\([0-9]\+\)-resp.json/\1/')
146         export DR_LOG_URL_"$NUM"="$(grep -o '"logURL":"[^"]*' "$file" | grep -w "feedlog" | cut -d '"' -f4)"
147         export DR_FILES_PUBLISHER_URL_"$NUM"="$(grep -o '"publishURL":"[^"]*' "$file" | cut -d '"' -f4)"
148       done
149       for file in $(ls drpub*); do
150         NUM=$(echo "$file" | sed 's/drpubConfig-\([0-9]\+\)-resp.json/\1/')
151         export DR_FILES_PUBLISHER_ID_"$NUM"="$(grep -o '"pubId":"[^"]*' "$file" | cut -d '"' -f4)"
152       done
153       for file in $(ls drsub*); do
154         NUM=$(echo "$file" | sed 's/drsubConfig-\([0-9]\+\)-resp.json/\1/')
155         export DR_FILES_SUBSCRIBER_ID_"$NUM"="$(grep -o '"subId":"[^"]*' "$file" | cut -d '"' -f4)"
156       done
157       for file in $(ls topics*); do
158         NUM=$(echo "$file" | sed 's/topicsConfig-\([0-9]\+\)-resp.json/\1/')
159         export MR_FILES_PUBLISHER_CLIENT_ID_"$NUM"="$(grep -o '"mrClientId":"[^"]*' "$file" | cut -d '"' -f4)"
160       done
161     else
162       echo "No Response logged for Dmaap BusController Http POST Request..!"
163     fi
164     cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
165   env:
166   {{- range $cred := $dot.Values.credentials }}
167   - name: {{ $cred.name }}
168     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
169   {{- end }}
170   volumeMounts:
171   - mountPath: /opt/app/config/cache
172     name: dbc-response-cache
173   - mountPath: /config-input
174     name: app-config-input
175   - mountPath: /config
176     name: app-config
177   resources:
178     limits:
179       cpu: 200m
180       memory: 250Mi
181     requests:
182       cpu: 100m
183       memory: 200Mi
184 {{- end -}}
185 {{- end -}}