aboutsummaryrefslogtreecommitdiffstats
path: root/kubernetes/common/common/templates/_dmaapProvisioning.tpl
blob: 8b3f19f5ef0ca3a2b5e3bc70652a483a5ba7c725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{{/*
################################################################################
#   Copyright (C) 2021 Nordix Foundation.                                      #
#   Copyright (c) 2022 J. F. Lucas.  All rights reserved.                      #
#                                                                              #
#   Licensed under the Apache License, Version 2.0 (the "License");            #
#   you may not use this file except in compliance with the License.           #
#   You may obtain a copy of the License at                                    #
#                                                                              #
#       http://www.apache.org/licenses/LICENSE-2.0                             #
#                                                                              #
#   Unless required by applicable law or agreed to in writing, software        #
#   distributed under the License is distributed on an "AS IS" BASIS,          #
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
#   See the License for the specific language governing permissions and        #
#   limitations under the License.                                             #
################################################################################
*/}}

{{/*
  This template generates a Kubernetes init containers common template to enable applications to provision
  DMaaP feeds (on Data Router), with associated authorization.
  DMaap Bus Controller endpoints are used to provision:

  - Feed on DR, with associated user authentication.

  common.dmaap.provisioning.initContainer:
  This template make use of Dmaap Bus Controller docker image to create resources on Dmaap Data Router
  microservice, with the help of dbc-client.sh script it makes use of Bus Controller API to create Feeds.
  If the resource creation is successful via script response is logged back at particular location with
  appropriate naming convention.

  More details can be found at :
  (https://wiki.onap.org/pages/viewpage.action?pageId=103417564)

  The template directly references data in .Values, and indirectly (through its
  use of templates from the ONAP "common" collection) references data in .Release.

  Parameter for _dmaapProvisioning to be defined in values.yaml
  # DataRouter Feed Configuration
  drFeedConfig:
    - feedName: bulk_pm_feed
      owner: dcaecm
      feedVersion: 0.0
      asprClassification: unclassified
      feedDescription: DFC Feed Creation

  # DataRouter Publisher Configuration
  drPubConfig:
    - feedName: bulk_pm_feed
      dcaeLocationName: loc00

  # DataRouter Subscriber Configuration
  drSubConfig:
    - feedName: bulk_pm_feed
      decompress: True
      dcaeLocationName: loc00
      privilegedSubscriber: True
      deliveryURL: https://dcae-pm-mapper:8443/delivery

  # ConfigMap Configuration for DR Feed, Dr_Publisher, Dr_Subscriber
  volumes:
    - name: feeds-config
      path: /opt/app/config/feeds
    - name: drpub-config
      path: /opt/app/config/dr_pubs
    - name: drsub-config
      path: /opt/app/config/dr_subs

  In deployments/jobs/stateful include:
  initContainers:
  {{- include "common.dmaap.provisioning.initContainer" . | nindent XX }}
  volumes:
  {{- include "common.dmaap.provisioning._volumes" . | nindent XX -}}
*/}}

{{- define "common.dmaap.provisioning._volumeMounts" -}}
{{- $dot := default . .dot -}}
- mountPath: /opt/app/config/cache
  name: dbc-response-cache
{{- range $name, $volume := $dot.Values.volumes }}
- name: {{ $volume.name }}
  mountPath: {{ $volume.path }}
{{- end }}
{{- end -}}

{{- define "common.dmaap.provisioning._volumes" -}}
{{- $dot := default . .dot -}}
- name: dbc-response-cache
  emptyDir: {}
{{- range $name, $volume := $dot.Values.volumes }}
- name: {{ $volume.name }}
  configMap:
    defaultMode: 420
    name: {{ include "common.fullname" $dot }}-{{ printf "%s" $volume.name }}
{{- end }}
{{- end -}}

{{- define "common.dmaap.provisioning.initContainer" -}}
{{- $dot := default . .dot -}}
{{- $drFeedConfig := default $dot.Values.drFeedConfig .drFeedConfig -}}
{{- if $drFeedConfig -}}
- name: {{ include "common.name" $dot }}-init-dmaap-provisioning
  image: {{ include "repositoryGenerator.image.dbcClient" $dot }}
  imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
  env:
  - name: PROTO
    value: "http"
  - name: PORT
    value: "8080"
  - name: RESP_CACHE
    value: /opt/app/config/cache
  - name: REQUESTID
    value: "{{ include "common.name" $dot }}-dmaap-provisioning"
  {{- range $cred := $dot.Values.credentials }}
  - name: {{ $cred.name }}
    {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
  {{- end }}
  volumeMounts:
  {{- include "common.dmaap.provisioning._volumeMounts" $dot | trim | nindent 2 }}
  resources: {{ include "common.resources" $dot | nindent 1 }}
- name: {{ include "common.name" $dot }}-init-merge-config
  image: {{ include "repositoryGenerator.image.envsubst" $dot }}
  imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
  command:
  - /bin/sh
  args:
  - -c
  - |
    set -uex -o pipefail
    if [ -d /opt/app/config/cache ]; then
      cd /opt/app/config/cache
      for file in $(ls feed*); do
        NUM=$(echo "$file" | sed 's/feedConfig-\([0-9]\+\)-resp.json/\1/')
        export DR_LOG_URL_"$NUM"="$(grep -o '"logURL":"[^"]*' "$file" | grep -w "feedlog" | cut -d '"' -f4)"
        export DR_FILES_PUBLISHER_URL_"$NUM"="$(grep -o '"publishURL":"[^"]*' "$file" | cut -d '"' -f4)"
      done
      for file in $(ls drpub*); do
        NUM=$(echo "$file" | sed 's/drpubConfig-\([0-9]\+\)-resp.json/\1/')
        export DR_FILES_PUBLISHER_ID_"$NUM"="$(grep -o '"pubId":"[^"]*' "$file" | cut -d '"' -f4)"
      done
      for file in $(ls drsub*); do
        NUM=$(echo "$file" | sed 's/drsubConfig-\([0-9]\+\)-resp.json/\1/')
        export DR_FILES_SUBSCRIBER_ID_"$NUM"="$(grep -o '"subId":"[^"]*' "$file" | cut -d '"' -f4)"
      done
      for file in $(ls topics*); do
        NUM=$(echo "$file" | sed 's/topicsConfig-\([0-9]\+\)-resp.json/\1/')
        export MR_FILES_PUBLISHER_CLIENT_ID_"$NUM"="$(grep -o '"mrClientId":"[^"]*' "$file" | cut -d '"' -f4)"
      done
    else
      echo "No Response logged for Dmaap BusController Http POST Request..!"
    fi
    cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done
  env:
  {{- range $cred := $dot.Values.credentials }}
  - name: {{ $cred.name }}
    {{- include "common.secret.envFromSecretFast" (dict "global" $dot "uid" $cred.uid "key" $cred.key) | nindent 4 }}
  {{- end }}
  volumeMounts:
  - mountPath: /opt/app/config/cache
    name: dbc-response-cache
  - mountPath: /config-input
    name: app-config-input
  - mountPath: /config
    name: app-config
  resources:
    limits:
      cpu: 200m
      memory: 250Mi
    requests:
      cpu: 100m
      memory: 200Mi
{{- end -}}
{{- end -}}