[DMAAP] Remove AAF dependency
[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: PROTO
108     value: "http"
109   - name: PORT
110     value: "8080"
111   - name: RESP_CACHE
112     value: /opt/app/config/cache
113   - name: REQUESTID
114     value: "{{ include "common.name" $dot }}-dmaap-provisioning"
115   {{- range $cred := $dot.Values.credentials }}
116   - name: {{ $cred.name }}
117     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
118   {{- end }}
119   volumeMounts:
120   {{- include "common.dmaap.provisioning._volumeMounts" $dot | trim | nindent 2 }}
121   resources: {{ include "common.resources" $dot | nindent 1 }}
122 - name: {{ include "common.name" $dot }}-init-merge-config
123   image: {{ include "repositoryGenerator.image.envsubst" $dot }}
124   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
125   command:
126   - /bin/sh
127   args:
128   - -c
129   - |
130     set -uex -o pipefail
131     if [ -d /opt/app/config/cache ]; then
132       cd /opt/app/config/cache
133       for file in $(ls feed*); do
134         NUM=$(echo "$file" | sed 's/feedConfig-\([0-9]\+\)-resp.json/\1/')
135         export DR_LOG_URL_"$NUM"="$(grep -o '"logURL":"[^"]*' "$file" | grep -w "feedlog" | cut -d '"' -f4)"
136         export DR_FILES_PUBLISHER_URL_"$NUM"="$(grep -o '"publishURL":"[^"]*' "$file" | cut -d '"' -f4)"
137       done
138       for file in $(ls drpub*); do
139         NUM=$(echo "$file" | sed 's/drpubConfig-\([0-9]\+\)-resp.json/\1/')
140         export DR_FILES_PUBLISHER_ID_"$NUM"="$(grep -o '"pubId":"[^"]*' "$file" | cut -d '"' -f4)"
141       done
142       for file in $(ls drsub*); do
143         NUM=$(echo "$file" | sed 's/drsubConfig-\([0-9]\+\)-resp.json/\1/')
144         export DR_FILES_SUBSCRIBER_ID_"$NUM"="$(grep -o '"subId":"[^"]*' "$file" | cut -d '"' -f4)"
145       done
146       for file in $(ls topics*); do
147         NUM=$(echo "$file" | sed 's/topicsConfig-\([0-9]\+\)-resp.json/\1/')
148         export MR_FILES_PUBLISHER_CLIENT_ID_"$NUM"="$(grep -o '"mrClientId":"[^"]*' "$file" | cut -d '"' -f4)"
149       done
150     else
151       echo "No Response logged for Dmaap BusController Http POST Request..!"
152     fi
153     cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
154   env:
155   {{- range $cred := $dot.Values.credentials }}
156   - name: {{ $cred.name }}
157     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
158   {{- end }}
159   volumeMounts:
160   - mountPath: /opt/app/config/cache
161     name: dbc-response-cache
162   - mountPath: /config-input
163     name: app-config-input
164   - mountPath: /config
165     name: app-config
166   resources:
167     limits:
168       cpu: 200m
169       memory: 250Mi
170     requests:
171       cpu: 100m
172       memory: 200Mi
173 {{- end -}}
174 {{- end -}}