Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / common / templates / _dmaapProvisioning.tpl
1 {{/*
2 ################################################################################
3 #   Copyright (C) 2021 Nordix Foundation.                                      #
4 #   Copyright (c) 2022-2023 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) for DCAE microservices, with associated authorization.
23   DMaap Data Router (DR) endpoints are used to provision:
24   - Feeds on DR, with associated user authentication.
25   - Subscribers to feeds on DR, to provide DR with username, password, and URL needed to deliver
26     files to subscribers.
27
28   common.dmaap.provisioning.initContainer:
29   This template creates an initContainer with some associated volumes.  The initContainer
30   (oom/kubernetes/dmaap-datarouter/drprov-client) runs a script (drprov-client.sh) that uses the
31   DR provisioning API to create the feeds and subscribers needed by a microservice.  The script
32   updates the microservice's configuration to supply information needed to access the feeds. The
33   configuration information comes from two volumes that are created by the dcaegen2-services-common
34   templates.
35   - app-config-input: comes from a configMap generated from the microservice's values.yaml file.
36     It may contain references to environment variables as placeholders for feed information that
37     will become available after feeds are provisioned.
38   - app-config: this template will copy the configuration file from the app-config-input volume,
39     replaced the environment variable references with the actual values for feed information, based
40     on data returned by the DR provisioning API.
41
42   The template directly references data in .Values, and indirectly (through its
43   use of templates from the ONAP "common" collection) references data in .Release.
44
45   Parameters for _dmaapProvisioning to be defined in values.yaml:
46
47   # DataRouter Feed Configuration
48   # (Note that DR configures publishers as part of the feed.)
49   drFeedConfig:
50     - feedName: bulk_pm_feed
51       feedVersion: 0.0
52       classification: unclassified
53       feedDescription: DFC Feed Creation
54       publisher:
55         username: xyz
56         password: xyz
57
58   # DataRouter Subscriber Configuration
59   drSubConfig:
60     - feedName: bulk_pm_feed
61       feedVersion: 0.0
62       decompress: True
63       privilegedSubscriber: True
64       deliveryURL: https://dcae-pm-mapper:8443/delivery
65
66   # ConfigMap Configuration for DR Feed, Dr_Subscriber
67   volumes:
68     - name: feeds-config
69       path: /opt/app/config/feeds
70     - name: drsub-config
71       path: /opt/app/config/dr_subs
72
73   In deployments/jobs/stateful include:
74   initContainers:
75   {{- include "common.dmaap.provisioning.initContainer" . | nindent XX }}
76   volumes:
77   {{- include "common.dmaap.provisioning._volumes" . | nindent XX -}}
78 */}}
79
80 {{- define "common.dmaap.provisioning._volumeMounts" -}}
81 {{- $dot := default . .dot -}}
82 - mountPath: /config-input
83   name: app-config-input
84 - mountPath: /config
85   name: app-config
86 {{- range $name, $volume := $dot.Values.volumes }}
87 - name: {{ $volume.name }}
88   mountPath: {{ $volume.path }}
89 {{- end }}
90 {{- end -}}
91
92 {{- define "common.dmaap.provisioning._volumes" -}}
93 {{- $dot := default . .dot -}}
94 {{- range $name, $volume := $dot.Values.volumes }}
95 - name: {{ $volume.name }}
96   configMap:
97     defaultMode: 420
98     name: {{ include "common.fullname" $dot }}-{{ printf "%s" $volume.name }}
99 {{- end }}
100 {{- end -}}
101
102 {{- define "common.dmaap.provisioning.initContainer" -}}
103 {{- $dot := default . .dot -}}
104 {{- $drNeedProvisioning := or $dot.Values.drFeedConfig $dot.Values.drSubConfig -}}
105 {{- if $drNeedProvisioning -}}
106 - name: {{ include "common.name" $dot }}-init-dmaap-provisioning
107   image: {{ include "repositoryGenerator.image.drProvClient" $dot }}
108   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
109   env:
110   {{- range $cred := $dot.Values.credentials }}
111   - name: {{ $cred.name }}
112     {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
113   {{- end }}
114   volumeMounts:
115   {{- include "common.dmaap.provisioning._volumeMounts" $dot | trim | nindent 2 }}
116   resources: {{ include "common.resources" $dot | nindent 4 }}
117 {{- end -}}
118 {{- end -}}