@sap/cds-dk 4.9.6 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/bin/activate.js +4 -4
- package/bin/add.js +11 -5
- package/bin/bind.js +16 -28
- package/bin/build/all.js +2 -2
- package/bin/build/index.js +12 -19
- package/bin/cds.js +16 -17
- package/bin/compile/index.js +12 -3
- package/bin/deploy/index.js +14 -14
- package/bin/deploy/to-hana.js +4 -4
- package/bin/deploy/to-sqlite.js +1 -1
- package/bin/env.js +13 -4
- package/bin/eval.js +1 -1
- package/bin/fix-redirects.js +1 -1
- package/bin/import.js +44 -179
- package/bin/repl.js +1 -1
- package/bin/watch.js +10 -15
- package/lib/bind/BindingManager.js +87 -0
- package/lib/bind/bindingResolver.js +14 -85
- package/lib/bind/bindingUtil.js +18 -11
- package/lib/bind/cfKeyProvider.js +58 -29
- package/lib/bind/kubernetesCredentialsProvider.js +44 -21
- package/lib/bind/userCdsrcJsonStorageProvider.js +12 -18
- package/lib/cds.js +13 -0
- package/lib/client/base_command.js +3 -2
- package/lib/client/extend.js +6 -7
- package/lib/client/helper/fs_helper.js +7 -8
- package/lib/client/settings_manager.js +14 -10
- package/lib/compile/index.js +9 -10
- package/lib/compile/openapi/csdl2openapi.js +151 -43
- package/lib/compile/openapi/index.js +2 -2
- package/lib/compile/to-xsuaa.js +3 -2
- package/lib/import/common.js +342 -27
- package/lib/import/importapi.js +81 -13
- package/lib/import/message.js +4 -4
- package/lib/import/odata/index.js +141 -0
- package/lib/import/{utils → odata/metadataconverter}/MetadataConverter.js +2 -2
- package/lib/import/{utils → odata/metadataconverter}/MetadataConverterFactory.js +1 -1
- package/lib/import/{utils → odata/util}/MultiMap.js +0 -0
- package/lib/import/{v2parser.js → odata/v2parser.js} +405 -468
- package/lib/import/{v4parser.js → odata/v4parser.js} +311 -322
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Aggregation.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Authorization.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Capabilities.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Core.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Measures.V1.json +0 -0
- package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Validation.V1.json +0 -0
- package/lib/import/openapi/importOpenAPI.js +521 -0
- package/lib/import/openapi/index.js +19 -0
- package/lib/import/openapi/utilities.js +38 -0
- package/lib/index.js +1 -1
- package/lib/init/constants.js +7 -2
- package/lib/init/index.js +10 -3
- package/lib/init/template/_merging/existences.js +79 -19
- package/lib/init/template/approuter/files/mta.yaml.hbs +25 -11
- package/lib/init/template/approuter/files/package.json +1 -1
- package/lib/init/template/approuter/files/xs-app.json.hbs +7 -0
- package/lib/init/template/approuter/index.js +61 -54
- package/lib/init/template/auditlog/index.js +2 -2
- package/lib/init/template/data/index.js +2 -2
- package/lib/init/template/hana/files/mta.yaml.hbs +17 -17
- package/lib/init/template/hana/index.js +8 -4
- package/lib/init/template/helm/index.js +39 -0
- package/lib/init/template/helm/update/index.js +28 -0
- package/lib/init/template/java/index.js +7 -9
- package/lib/init/template/kibana-logging/index.js +5 -6
- package/lib/init/template/mta/index.js +4 -4
- package/lib/init/template/mtx/files/java/package.json +9 -9
- package/lib/init/template/mtx/files/mta.yaml.hbs +0 -7
- package/lib/init/template/mtx/files/xs-security.json.hbs +11 -20
- package/lib/init/template/mtx/index.js +50 -57
- package/lib/init/template/nodejs/files/package.json.hbs +2 -2
- package/lib/init/template/notebook/index.js +2 -0
- package/lib/init/template/templateBase.js +6 -4
- package/lib/init/template/xsuaa/index.js +9 -5
- package/lib/init/util/fsUtil.js +25 -10
- package/lib/init/util/logger.js +1 -1
- package/lib/init/util/mvnArchetypeUtil.js +4 -10
- package/lib/init/util/projectReader.js +16 -8
- package/lib/init/util/templateUtil.js +30 -34
- package/lib/k8s/ChartAdder.js +65 -0
- package/lib/k8s/ChartBuilder.js +186 -0
- package/lib/k8s/Context.js +71 -0
- package/lib/k8s/ImageUtil.js +21 -0
- package/lib/k8s/Model.d.ts +53 -0
- package/lib/k8s/auditlog/index.js +29 -0
- package/lib/k8s/auditlog/templates/auditlog.yaml +1 -0
- package/lib/k8s/buildModel.js +70 -0
- package/lib/k8s/connectivity/index.js +74 -0
- package/lib/k8s/connectivity/templates/connectivity-binding.yaml +9 -0
- package/lib/k8s/connectivity/templates/connectivity-proxy-info.yaml +16 -0
- package/lib/k8s/connectivity/templates/connectivity.yaml +1 -0
- package/lib/k8s/deployment/index.js +81 -0
- package/lib/k8s/deployment/subchart/Chart.yaml +6 -0
- package/lib/k8s/deployment/subchart/templates/_helpers.tpl +156 -0
- package/lib/k8s/deployment/subchart/templates/api-rule.yaml +24 -0
- package/lib/k8s/deployment/subchart/templates/deployment.yaml +110 -0
- package/lib/k8s/deployment/subchart/templates/network-policy.yaml +16 -0
- package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +11 -0
- package/lib/k8s/deployment/subchart/templates/secret.yaml +10 -0
- package/lib/k8s/deployment/subchart/templates/service-binding.yaml +27 -0
- package/lib/k8s/deployment/subchart/templates/service.yaml +11 -0
- package/lib/k8s/deployment/subchart/values-lint.yaml +8 -0
- package/lib/k8s/deployment/subchart/values.schema.json +449 -0
- package/lib/k8s/deployment/subchart/values.yaml +76 -0
- package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +81 -0
- package/lib/k8s/destinations/index.js +40 -0
- package/lib/k8s/destinations/lib.js +16 -0
- package/lib/k8s/destinations/templates/destinations.yaml +1 -0
- package/lib/k8s/docker/push.js +8 -0
- package/lib/k8s/event-mesh/index.js +53 -0
- package/lib/k8s/event-mesh/lib.js +9 -0
- package/lib/k8s/event-mesh/templates/event-mesh.yaml +1 -0
- package/lib/k8s/hana-deployer/index.js +38 -0
- package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +41 -0
- package/lib/k8s/helm/Release.js +80 -0
- package/lib/k8s/html5-apps-deployer/index.js +43 -0
- package/lib/k8s/html5-apps-deployer/templates/_html5_deployment_helpers.tpl +16 -0
- package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +53 -0
- package/lib/k8s/html5-apps-repo-host/index.js +26 -0
- package/lib/k8s/html5-apps-repo-host/lib.js +16 -0
- package/lib/k8s/html5-apps-repo-host/templates/html5-apps-repo-host.yaml +1 -0
- package/lib/k8s/index.js +153 -0
- package/lib/k8s/modules.js +36 -0
- package/lib/k8s/multitenancy/index.js +24 -0
- package/lib/k8s/multitenancy/lib.js +25 -0
- package/lib/k8s/multitenancy/templates/saas-registry.yaml +19 -0
- package/lib/k8s/readProject.js +14 -0
- package/lib/k8s/resources/helm/chart/templates/NOTES.txt +11 -0
- package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +221 -0
- package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +167 -0
- package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +103 -0
- package/lib/k8s/util.js +186 -0
- package/lib/k8s/wrapFeature.js +55 -0
- package/lib/k8s/xsuaa/index.js +64 -0
- package/lib/k8s/xsuaa/lib.js +14 -0
- package/lib/k8s/xsuaa/templates/xsuaa.yaml +1 -0
- package/lib/util/exec.js +1 -1
- package/lib/util/write.js +1 -1
- package/lib/watch/node-watch.js +43 -14
- package/npm-shrinkwrap.json +914 -2745
- package/package.json +5 -5
- package/lib/import/index.js +0 -235
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
{{/*
|
|
2
|
+
Generate VCAP_APPLICATION
|
|
3
|
+
*/}}
|
|
4
|
+
{{- define "cap.vcapApplication" -}}
|
|
5
|
+
{{- $deploymentHost := include "cap.deploymentHost" . -}}
|
|
6
|
+
{{- $VCAP_APPLICATION := dict "application_uris" (list (print $deploymentHost "." .Values.global.domain)) }}
|
|
7
|
+
{{- $VCAP_APPLICATION | toJson }}
|
|
8
|
+
{{- end -}}
|
|
9
|
+
|
|
10
|
+
{{/*
|
|
11
|
+
Add custom env variables
|
|
12
|
+
*/}}
|
|
13
|
+
{{- define "cap.env" -}}
|
|
14
|
+
{{- if . -}}
|
|
15
|
+
{{- range $name, $value := . }}
|
|
16
|
+
- name: {{ $name | quote }}
|
|
17
|
+
value: {{ $value | quote }}
|
|
18
|
+
{{- end -}}
|
|
19
|
+
{{- end -}}
|
|
20
|
+
{{- end -}}
|
|
21
|
+
|
|
22
|
+
{{- define "cap.bindingsVolumes" -}}
|
|
23
|
+
{{- if $.Values.newBindings -}}
|
|
24
|
+
{{- include "cap.newBindingsVolumes" $ }}
|
|
25
|
+
{{- else -}}
|
|
26
|
+
{{- include "cap.oldBindingsVolumes" $ }}
|
|
27
|
+
{{- end -}}
|
|
28
|
+
{{- end -}}
|
|
29
|
+
|
|
30
|
+
{{/*
|
|
31
|
+
Old Service Bindings: volumes
|
|
32
|
+
*/}}
|
|
33
|
+
{{- define "cap.oldBindingsVolumes" -}}
|
|
34
|
+
{{- $ := . -}}
|
|
35
|
+
{{ range $bindingName, $binding := .deployment.bindings -}}
|
|
36
|
+
{{- $secret := include "cap.bindingSecretName" (dict "Release" $.Release "name" $.name "bindingName" $bindingName "binding" $binding) }}
|
|
37
|
+
- name: {{ $bindingName }}-secret
|
|
38
|
+
secret:
|
|
39
|
+
secretName: {{ $secret | quote }}
|
|
40
|
+
{{- if and (eq $bindingName "db") $.deployment.multitenancy }}
|
|
41
|
+
# the "plan" property must not be in the secret for the service manager
|
|
42
|
+
# it would be used as plan for HANA
|
|
43
|
+
items:
|
|
44
|
+
- key: clientid
|
|
45
|
+
path: clientid
|
|
46
|
+
- key: clientsecret
|
|
47
|
+
path: clientsecret
|
|
48
|
+
- key: sm_url
|
|
49
|
+
path: sm_url
|
|
50
|
+
- key: url
|
|
51
|
+
path: url
|
|
52
|
+
- key: xsappname
|
|
53
|
+
path: xsappname
|
|
54
|
+
{{- end -}}
|
|
55
|
+
{{- if eq $.deployment.language "Node" }}
|
|
56
|
+
- name: {{ $bindingName }}-metadata
|
|
57
|
+
secret:
|
|
58
|
+
secretName: {{ $secret | quote }}
|
|
59
|
+
optional: true
|
|
60
|
+
items:
|
|
61
|
+
- key: label
|
|
62
|
+
path: label
|
|
63
|
+
- key: plan
|
|
64
|
+
path: plan
|
|
65
|
+
- key: tags
|
|
66
|
+
path: tags
|
|
67
|
+
{{- end -}}
|
|
68
|
+
{{- end -}}
|
|
69
|
+
{{- end -}}
|
|
70
|
+
|
|
71
|
+
{{/*
|
|
72
|
+
New Service Bindings: volumes
|
|
73
|
+
*/}}
|
|
74
|
+
{{- define "cap.newBindingsVolumes" -}}
|
|
75
|
+
{{- $ := . -}}
|
|
76
|
+
{{ range $bindingName, $binding := .deployment.bindings -}}
|
|
77
|
+
{{- $secret := include "cap.bindingSecretName" (dict "Release" $.Release "name" $.name "bindingName" $bindingName "binding" $binding) }}
|
|
78
|
+
- name: {{ $bindingName }}-secret
|
|
79
|
+
secret:
|
|
80
|
+
secretName: {{ $secret | quote }}
|
|
81
|
+
{{- end -}}
|
|
82
|
+
{{- end -}}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
{{- define "cap.bindingsEnv" -}}
|
|
86
|
+
{{- if $.Values.newBindings -}}
|
|
87
|
+
{{- include "cap.newBindingsEnv" $ }}
|
|
88
|
+
{{- else -}}
|
|
89
|
+
{{- include "cap.oldBindingsEnv" $ }}
|
|
90
|
+
{{- end -}}
|
|
91
|
+
{{- end -}}
|
|
92
|
+
|
|
93
|
+
{{/*
|
|
94
|
+
Old Service Bindings: env vars
|
|
95
|
+
*/}}
|
|
96
|
+
{{- define "cap.oldBindingsEnv" }}
|
|
97
|
+
{{- $ := . }}
|
|
98
|
+
{{- if eq .deployment.language "Java" }}
|
|
99
|
+
{{- range $key, $binding := .deployment.bindings }}
|
|
100
|
+
{{- $cleanKey := $key | upper | replace "-" "" | replace "_" "" | replace "." "" }}
|
|
101
|
+
{{- $prefix := print "CDS_ENVIRONMENT_K8S_SERVICEBINDINGS_" $cleanKey }}
|
|
102
|
+
{{- $secret := default (print $.Release.Name "-" $.name "-" $key) $binding.secret }}
|
|
103
|
+
- name: {{ $prefix }}_SERVICE
|
|
104
|
+
valueFrom:
|
|
105
|
+
secretKeyRef:
|
|
106
|
+
name: {{ $secret | quote }}
|
|
107
|
+
key: label
|
|
108
|
+
- name: {{ $prefix }}_PLAN
|
|
109
|
+
valueFrom:
|
|
110
|
+
secretKeyRef:
|
|
111
|
+
name: {{ $secret | quote }}
|
|
112
|
+
key: plan
|
|
113
|
+
optional: true
|
|
114
|
+
- name: {{ $prefix }}_SECRETSPATH
|
|
115
|
+
value: /etc/secrets/cds/requires/{{ $key }}/credentials
|
|
116
|
+
{{- end }}
|
|
117
|
+
{{- else }}
|
|
118
|
+
{{- /* Read credentials from file system */ -}}
|
|
119
|
+
- name: CDS_CONFIG
|
|
120
|
+
value: /etc/secrets/cds
|
|
121
|
+
{{ end }}
|
|
122
|
+
{{- end }}
|
|
123
|
+
|
|
124
|
+
{{/*
|
|
125
|
+
New Service Bindings: env vars
|
|
126
|
+
*/}}
|
|
127
|
+
{{- define "cap.newBindingsEnv" }}
|
|
128
|
+
- name: SERVICE_BINDING_ROOT
|
|
129
|
+
value: /bindings
|
|
130
|
+
{{- end }}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
{{- define "cap.bindingsVolumeMounts" -}}
|
|
134
|
+
{{- if $.Values.newBindings -}}
|
|
135
|
+
{{- include "cap.newBindingsVolumeMounts" $ }}
|
|
136
|
+
{{- else -}}
|
|
137
|
+
{{- include "cap.oldBindingsVolumeMounts" $ }}
|
|
138
|
+
{{- end -}}
|
|
139
|
+
{{- end -}}
|
|
140
|
+
|
|
141
|
+
{{/*
|
|
142
|
+
Old Service Bindings: volume mounts
|
|
143
|
+
*/}}
|
|
144
|
+
{{- define "cap.oldBindingsVolumeMounts" }}
|
|
145
|
+
{{- $ := . -}}
|
|
146
|
+
{{- range $key, $binding := .deployment.bindings }}
|
|
147
|
+
- name: {{ $key }}-secret
|
|
148
|
+
mountPath: /etc/secrets/cds/requires/{{ $key }}/credentials
|
|
149
|
+
readOnly: true
|
|
150
|
+
{{- if eq $.deployment.language "Node" }}
|
|
151
|
+
- name: {{ $key }}-metadata
|
|
152
|
+
mountPath: /etc/secrets/cds/requires/{{ $key }}/vcap
|
|
153
|
+
readOnly: true
|
|
154
|
+
{{- end }}
|
|
155
|
+
{{- end }}
|
|
156
|
+
{{- end }}
|
|
157
|
+
|
|
158
|
+
{{/*
|
|
159
|
+
New Service Bindings: volume mounts
|
|
160
|
+
*/}}
|
|
161
|
+
{{- define "cap.newBindingsVolumeMounts" }}
|
|
162
|
+
{{- $ := . -}}
|
|
163
|
+
{{- range $key, $binding := .deployment.bindings }}
|
|
164
|
+
- name: {{ $key }}-secret
|
|
165
|
+
mountPath: /bindings/{{ $key }}
|
|
166
|
+
readOnly: true
|
|
167
|
+
{{- end }}
|
|
168
|
+
{{- end }}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
{{/*
|
|
172
|
+
Get list of deployment names
|
|
173
|
+
*/}}
|
|
174
|
+
{{- define "cap.deploymentNames" -}}
|
|
175
|
+
{{- $defaultDeployments := (list "srv") -}}
|
|
176
|
+
{{- if .mtx -}}
|
|
177
|
+
{{- $_ := (append $defaultDeployments "mtx") -}}
|
|
178
|
+
{{- end -}}
|
|
179
|
+
{{ .deploymentNames | default $defaultDeployments | join ";" }}
|
|
180
|
+
{{- end -}}
|
|
181
|
+
|
|
182
|
+
{{/*
|
|
183
|
+
Create a default fully qualified app name.
|
|
184
|
+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
|
185
|
+
If release name contains chart name it will be used as a full name.
|
|
186
|
+
|
|
187
|
+
copied from web-application: web-application.fullname
|
|
188
|
+
|
|
189
|
+
*/}}
|
|
190
|
+
{{- define "cap.deploymentHost" -}}
|
|
191
|
+
{{- if .deployment.expose.host }}
|
|
192
|
+
{{- .deployment.expose.host }}
|
|
193
|
+
{{- else }}
|
|
194
|
+
{{- $name := (include "cap.web-application.fullname" .) }}
|
|
195
|
+
{{- if hasPrefix $name .Release.Namespace }}
|
|
196
|
+
{{- .Release.Namespace }}
|
|
197
|
+
{{- else }}
|
|
198
|
+
{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" }}
|
|
199
|
+
{{- end }}
|
|
200
|
+
{{- end }}
|
|
201
|
+
{{- end }}
|
|
202
|
+
|
|
203
|
+
{{- define "cap.web-application.fullname" -}}
|
|
204
|
+
{{- if .deployment.fullnameOverride }}
|
|
205
|
+
{{- .deployment.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
|
206
|
+
{{- else }}
|
|
207
|
+
{{- $name := default .name .deployment.nameOverride }}
|
|
208
|
+
{{- if contains $name .Release.Name }}
|
|
209
|
+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
|
210
|
+
{{- else }}
|
|
211
|
+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
|
212
|
+
{{- end }}
|
|
213
|
+
{{- end }}
|
|
214
|
+
{{- end }}
|
|
215
|
+
|
|
216
|
+
{{/*
|
|
217
|
+
Get FQDN of a deployment
|
|
218
|
+
*/}}
|
|
219
|
+
{{- define "cap.deploymentHostFull" -}}
|
|
220
|
+
{{ include "cap.deploymentHost" $ }}.{{ $.Values.global.domain }}
|
|
221
|
+
{{- end -}}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{{/*
|
|
2
|
+
Check for mandatory configuration options
|
|
3
|
+
*/}}
|
|
4
|
+
{{- define "cap.expect" -}}
|
|
5
|
+
{{- $root := first . -}}
|
|
6
|
+
{{- $vars := rest . -}}
|
|
7
|
+
{{- range $path := $vars -}}
|
|
8
|
+
{{- $var := $root.Values -}}
|
|
9
|
+
{{- $segments := regexSplit "\\." $path -1 -}}
|
|
10
|
+
{{- $context := (dict "var" $var) -}}
|
|
11
|
+
{{- range $segment := $segments -}}
|
|
12
|
+
{{- $var := (get $context "var") -}}
|
|
13
|
+
{{- $var := get $var $segment -}}
|
|
14
|
+
{{- if empty $var -}}
|
|
15
|
+
{{- fail (join "" (list "Expect .Values." $path)) -}}
|
|
16
|
+
{{- end -}}
|
|
17
|
+
{{- $context := set $context "var" $var -}}
|
|
18
|
+
{{- end -}}
|
|
19
|
+
{{- end -}}
|
|
20
|
+
{{- end -}}
|
|
21
|
+
|
|
22
|
+
{{/*
|
|
23
|
+
Labels for a component
|
|
24
|
+
*/}}
|
|
25
|
+
{{- define "cap.labels" -}}
|
|
26
|
+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
|
|
27
|
+
app.kubernetes.io/name: {{ .name }}
|
|
28
|
+
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
|
29
|
+
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
30
|
+
app.kubernetes.io/version: {{ .Chart.AppVersion }}
|
|
31
|
+
{{- end -}}
|
|
32
|
+
{{- define "cap.labelsWithRevision" -}}
|
|
33
|
+
{{- include "cap.labels" . }}
|
|
34
|
+
revision: "{{ .Release.Revision }}"
|
|
35
|
+
{{- end -}}
|
|
36
|
+
|
|
37
|
+
{{/*
|
|
38
|
+
Labels to select a component
|
|
39
|
+
*/}}
|
|
40
|
+
{{- define "cap.selectorLabels" -}}
|
|
41
|
+
app.kubernetes.io/name: {{ .name }}
|
|
42
|
+
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
43
|
+
{{- end -}}
|
|
44
|
+
|
|
45
|
+
{{/*
|
|
46
|
+
Image
|
|
47
|
+
*/}}
|
|
48
|
+
{{- define "cap.image.srv" -}}
|
|
49
|
+
{{- if .Values.srv.image.tag -}}
|
|
50
|
+
{{ .Values.srv.image.repository }}:{{ .Values.srv.image.tag }}
|
|
51
|
+
{{- else -}}
|
|
52
|
+
{{ .Values.srv.image.repository }}
|
|
53
|
+
{{- end -}}
|
|
54
|
+
{{- end -}}
|
|
55
|
+
|
|
56
|
+
{{- define "cap.image" -}}
|
|
57
|
+
{{- if .image.tag -}}
|
|
58
|
+
{{ .image.repository }}:{{ .image.tag }}
|
|
59
|
+
{{- else -}}
|
|
60
|
+
{{ .image.repository }}
|
|
61
|
+
{{- end -}}
|
|
62
|
+
{{- end -}}
|
|
63
|
+
|
|
64
|
+
{{/*
|
|
65
|
+
Image Pull Policy
|
|
66
|
+
*/}}
|
|
67
|
+
{{- define "cap.imagePullPolicy.srv" -}}
|
|
68
|
+
{{- if and (.Values.srv.image.tag) (ne .Values.srv.image.tag "latest") -}}
|
|
69
|
+
IfNotPresent
|
|
70
|
+
{{- else -}}
|
|
71
|
+
Always
|
|
72
|
+
{{- end -}}
|
|
73
|
+
{{- end -}}
|
|
74
|
+
|
|
75
|
+
{{- define "cap.imagePullPolicy" -}}
|
|
76
|
+
{{- if and (.image.tag) (ne .image.tag "latest") -}}
|
|
77
|
+
IfNotPresent
|
|
78
|
+
{{- else -}}
|
|
79
|
+
Always
|
|
80
|
+
{{- end -}}
|
|
81
|
+
{{- end -}}
|
|
82
|
+
|
|
83
|
+
{{/*
|
|
84
|
+
Image Pull Secrets
|
|
85
|
+
*/}}
|
|
86
|
+
{{- define "cap.imagePullSecrets" -}}
|
|
87
|
+
{{- if (and .Values.global.imagePullSecret .Values.global.imagePullSecret.name) }}
|
|
88
|
+
imagePullSecrets:
|
|
89
|
+
- name: {{ .Values.global.imagePullSecret.name | quote }}
|
|
90
|
+
{{- end -}}
|
|
91
|
+
{{- end -}}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
{{/*
|
|
95
|
+
Binding
|
|
96
|
+
*/}}
|
|
97
|
+
{{- define "cap.binding" -}}
|
|
98
|
+
apiVersion: services.cloud.sap.com/v1alpha1
|
|
99
|
+
kind: ServiceBinding
|
|
100
|
+
metadata:
|
|
101
|
+
name: {{ include "cap.bindingSecretName" $ | quote }}
|
|
102
|
+
namespace: {{ $.Release.Namespace }}
|
|
103
|
+
labels: {{- include "cap.labels" $ | nindent 4 }}
|
|
104
|
+
spec:
|
|
105
|
+
serviceInstanceName: {{ $.Release.Name }}-{{ $.binding.service }}
|
|
106
|
+
externalName: {{ include "cap.bindingSecretName" $ | quote }}
|
|
107
|
+
secretName: {{ include "cap.bindingSecretName" $ | quote }}
|
|
108
|
+
{{- end -}}
|
|
109
|
+
|
|
110
|
+
{{/*
|
|
111
|
+
Service Instance NEW
|
|
112
|
+
ternary dict ($.Files.Get $.service.config | fromJson)
|
|
113
|
+
*/}}
|
|
114
|
+
{{- define "cap.service-instance" -}}
|
|
115
|
+
{{- $key := .Template.Name | lower | regexFind "[a-zA-Z0-9_-]+.yaml" | replace ".yaml" "" | replace "-" "_" }}
|
|
116
|
+
{{- $service := get .Values $key }}
|
|
117
|
+
{{- if $service }}
|
|
118
|
+
{{- if or (not (hasKey $service "enabled")) $service.enabled }}
|
|
119
|
+
{{- $name := $key | replace "_" "-" }}
|
|
120
|
+
{{- $serviceParameters := $service.parameters | default (dict) }}
|
|
121
|
+
{{- $configParameters := (dict) }}
|
|
122
|
+
{{- if $service.config }}
|
|
123
|
+
{{- $configString := $.Files.Get $service.config }}
|
|
124
|
+
{{- if not $configString }}
|
|
125
|
+
{{- fail (print "Config file " $service.config " not found") }}
|
|
126
|
+
{{- end }}
|
|
127
|
+
{{- $_ := merge $configParameters (fromJson $configString) }}
|
|
128
|
+
{{- end }}
|
|
129
|
+
{{- $defaultParameters := $.defaultParameters | default dict }}
|
|
130
|
+
{{ $parameters := merge $serviceParameters $configParameters $defaultParameters }}
|
|
131
|
+
apiVersion: services.cloud.sap.com/v1alpha1
|
|
132
|
+
kind: ServiceInstance
|
|
133
|
+
metadata:
|
|
134
|
+
name: {{ include "cap.service-instance.serviceInstanceName" (dict "root" . "name" $name "service" $service) }}
|
|
135
|
+
namespace: {{ .Release.Namespace }}
|
|
136
|
+
labels: {{- include "cap.labels" (merge (dict "name" $name) .) | nindent 4 }}
|
|
137
|
+
spec:
|
|
138
|
+
serviceOfferingName: {{ $service.serviceOfferingName }}
|
|
139
|
+
servicePlanName: {{ $service.servicePlanName }}
|
|
140
|
+
externalName: {{ .Release.Namespace }}-{{ include "cap.service-instance.serviceInstanceName" (dict "root" . "name" $name "service" $service) }}
|
|
141
|
+
parameters:
|
|
142
|
+
{{ toYaml $parameters | indent 4 }}
|
|
143
|
+
{{- end -}}
|
|
144
|
+
{{- end -}}
|
|
145
|
+
{{- end -}}
|
|
146
|
+
|
|
147
|
+
{{/*
|
|
148
|
+
Service Instance
|
|
149
|
+
from web-application helm chart
|
|
150
|
+
*/}}
|
|
151
|
+
{{- define "cap.service-instance.serviceInstanceName" -}}
|
|
152
|
+
{{- if .service.fullnameOverride }}
|
|
153
|
+
{{- if gt (len .service.fullnameOverride) 63 }}
|
|
154
|
+
{{- fail (printf "name exceeds 63 characters: '%s'" .service.fullnameOverride) }}
|
|
155
|
+
{{- end }}
|
|
156
|
+
{{- .service.fullnameOverride }}
|
|
157
|
+
{{- else }}
|
|
158
|
+
{{- $name := .name }}
|
|
159
|
+
{{- if not (hasPrefix .root.Release.Name $name)}}
|
|
160
|
+
{{- $name = printf "%s-%s" .root.Release.Name $name }}
|
|
161
|
+
{{- end }}
|
|
162
|
+
{{- if gt (len $name) 63 }}
|
|
163
|
+
{{- fail (printf "name exceeds 63 characters: '%s'" $name) }}
|
|
164
|
+
{{- end }}
|
|
165
|
+
{{- $name }}
|
|
166
|
+
{{- end }}
|
|
167
|
+
{{- end }}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
{{/*
|
|
3
|
+
SAPCP Service Bindings: volume mounts
|
|
4
|
+
*/}}
|
|
5
|
+
{{- define "cap.sapcp.bindingsVolumeMounts" }}
|
|
6
|
+
{{- $ := . -}}
|
|
7
|
+
{{- range $key, $binding := .bindings }}
|
|
8
|
+
- name: {{ $key | replace "_" "-" }}-secret
|
|
9
|
+
mountPath: /etc/secrets/sapcp/{{ $key | replace "_" "-" }}/{{ $key }}
|
|
10
|
+
readOnly: true
|
|
11
|
+
{{- end }}
|
|
12
|
+
{{- end }}
|
|
13
|
+
|
|
14
|
+
{{/*
|
|
15
|
+
SAPCP Service Bindings: volumes
|
|
16
|
+
*/}}
|
|
17
|
+
{{- define "cap.sapcp.bindingsVolumes" -}}
|
|
18
|
+
{{- $ := . -}}
|
|
19
|
+
{{ range $bindingName, $binding := .bindings -}}
|
|
20
|
+
{{- $secret := include "cap.sapcp.bindingSecretName" (dict "root" $.root "name" $.name "bindingName" $bindingName "binding" $binding) }}
|
|
21
|
+
- name: {{ $bindingName | replace "_" "-" }}-secret
|
|
22
|
+
secret:
|
|
23
|
+
secretName: {{ $secret | quote }}
|
|
24
|
+
{{- end -}}
|
|
25
|
+
{{- end -}}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
{{/*
|
|
29
|
+
Binding Secret Name
|
|
30
|
+
*/}}
|
|
31
|
+
{{- define "cap.sapcp.bindingName" -}}
|
|
32
|
+
{{ print $.root.Release.Name "-" $.name "-" $.bindingName | replace "_" "-" }}
|
|
33
|
+
{{- end -}}
|
|
34
|
+
|
|
35
|
+
{{/*
|
|
36
|
+
SAPCP Service Bindings: bindings
|
|
37
|
+
*/}}
|
|
38
|
+
{{- define "cap.sapcp.bindings" -}}
|
|
39
|
+
{{- $ := . -}}
|
|
40
|
+
{{- range $name, $params := .bindings }}
|
|
41
|
+
{{- if not $params.fromSecret }}
|
|
42
|
+
---
|
|
43
|
+
apiVersion: services.cloud.sap.com/v1
|
|
44
|
+
kind: ServiceBinding
|
|
45
|
+
metadata:
|
|
46
|
+
namespace: {{ $.Release.Namespace }}
|
|
47
|
+
name: {{ include "cap.sapcp.bindingName" (dict "root" $.root "name" $.name "bindingName" $name) }}
|
|
48
|
+
labels: {{- include "cap.labels" $ | nindent 4 }}
|
|
49
|
+
spec:
|
|
50
|
+
serviceInstanceName: {{include "cap.sapcp.serviceInstanceName" (dict "binding" $params "release" $.Release.Name) }}
|
|
51
|
+
{{- if $params.externalName }}
|
|
52
|
+
externalName: {{ $params.externalName }}
|
|
53
|
+
{{- end }}
|
|
54
|
+
{{- if $params.secretName }}
|
|
55
|
+
secretName: {{ $params.secretName }}
|
|
56
|
+
{{- end }}
|
|
57
|
+
{{- if $params.parameters }}
|
|
58
|
+
parameters: {{ $params.parameters | toYaml | nindent 4 }}
|
|
59
|
+
{{- end }}
|
|
60
|
+
{{- if $params.parametersFrom }}
|
|
61
|
+
parametersFrom: {{ $params.parametersFrom | toYaml | nindent 4 }}
|
|
62
|
+
{{- end }}
|
|
63
|
+
{{- if $params.credentialsRotationPolicy }}
|
|
64
|
+
credentialsRotationPolicy: {{ $params.credentialsRotationPolicy | toYaml | nindent 4 }}
|
|
65
|
+
{{- end }}
|
|
66
|
+
{{- end }}
|
|
67
|
+
{{- end }}
|
|
68
|
+
{{- end }}
|
|
69
|
+
|
|
70
|
+
{{/*
|
|
71
|
+
Binding Secret Name
|
|
72
|
+
*/}}
|
|
73
|
+
{{- define "cap.sapcp.bindingSecretName" -}}
|
|
74
|
+
{{- $secretName := include "cap.sapcp.bindingName" . }}
|
|
75
|
+
{{- if .binding.fromSecret }}
|
|
76
|
+
{{- $secretName = .binding.fromSecret}}
|
|
77
|
+
{{- else if .binding.secretName }}
|
|
78
|
+
{{- $secretName = .binding.secretName }}
|
|
79
|
+
{{- end }}
|
|
80
|
+
{{- $secretName }}
|
|
81
|
+
{{- end }}
|
|
82
|
+
|
|
83
|
+
{{/*
|
|
84
|
+
Service Instance
|
|
85
|
+
from web-application helm chart
|
|
86
|
+
*/}}
|
|
87
|
+
{{- define "cap.sapcp.serviceInstanceName" -}}
|
|
88
|
+
{{- if .binding.serviceInstanceFullname }}
|
|
89
|
+
{{- if gt (len .binding.serviceInstanceFullname) 63 }}
|
|
90
|
+
{{- fail (printf "name exceeds 63 characters: '%s'" .binding.serviceInstanceFullname) }}
|
|
91
|
+
{{- end }}
|
|
92
|
+
{{- .binding.serviceInstanceFullname }}
|
|
93
|
+
{{- else }}
|
|
94
|
+
{{- $name := .binding.serviceInstanceName }}
|
|
95
|
+
{{- if not (hasPrefix .release $name)}}
|
|
96
|
+
{{- $name = printf "%s-%s" .release $name }}
|
|
97
|
+
{{- end }}
|
|
98
|
+
{{- if gt (len $name) 63 }}
|
|
99
|
+
{{- fail (printf "name exceeds 63 characters: '%s'" $name) }}
|
|
100
|
+
{{- end }}
|
|
101
|
+
{{- $name }}
|
|
102
|
+
{{- end }}
|
|
103
|
+
{{- end }}
|
package/lib/k8s/util.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
|
|
2
|
+
const { glob } = require('./modules');
|
|
3
|
+
const Path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { $, exec, execSync } = require('../util/exec');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {string} msg
|
|
10
|
+
* @returns {never}
|
|
11
|
+
*/
|
|
12
|
+
function throwError(msg = 'Internal Error', ...args) {
|
|
13
|
+
if (Array.isArray(msg)) {
|
|
14
|
+
msg = format(msg, ...args);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
throw new Error(msg);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resource(path, plugin) {
|
|
21
|
+
return plugin == undefined ? Path.join(__dirname, 'resources', path)
|
|
22
|
+
: Path.join(__dirname, plugin, path)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function cp(from, to) {
|
|
26
|
+
const content = fs.readFileSync(from);
|
|
27
|
+
fs.writeFileSync(to, content);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function format(text, ...args) {
|
|
31
|
+
if (Array.isArray(text)) {
|
|
32
|
+
text = text.slice(0,-1).map( (str, index) => `${str}$${index}` ).concat(text.slice(-1)).join('');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const forTTY = process.stdout.isTTY;
|
|
36
|
+
if (forTTY) {
|
|
37
|
+
text = text
|
|
38
|
+
.replace(/\n# ([^\n]*)\n/g, `\n\x1b[1m$1\x1b[0m\n`)
|
|
39
|
+
.replace(/ \*([^*]+)\*/g, ` \x1b[1m$1\x1b[0m`)
|
|
40
|
+
.replace(/ _([^_]+)_/g, ` \x1b[4m$1\x1b[0m`);
|
|
41
|
+
} else {
|
|
42
|
+
text = text
|
|
43
|
+
.replace(/\n# ([^\n]*)\n/g, `\n$\n`)
|
|
44
|
+
.replace(/ \*([^*]+)\*/g, `$1`)
|
|
45
|
+
.replace(/ _([^_]+)_/g, `$1`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return text.replace(/\$(\d+)/, (match, value) => args[value]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function help(text) {
|
|
52
|
+
console.log(format(text))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function checkDebug(category) {
|
|
56
|
+
const debug = (process.env.DEBUG || '').split(/\W+/);
|
|
57
|
+
return debug.indexOf(category)>=0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function dirExists(path) {
|
|
61
|
+
try {
|
|
62
|
+
const stat = fs.statSync(path);
|
|
63
|
+
return stat.isDirectory();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
66
|
+
return false;
|
|
67
|
+
else
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function globSingleFile(pattern) {
|
|
73
|
+
const result = glob.sync(pattern);
|
|
74
|
+
if (result.length !== 1) throwError `Expect 1 file matching the pattern *${ pattern }*. Found ${ result.length }.`;
|
|
75
|
+
return result[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getProperty(obj, name, handleUndefined) {
|
|
79
|
+
const path = name.split('.');
|
|
80
|
+
for (const field of path) {
|
|
81
|
+
if (typeof obj !== 'object') throwError `Invalid property *${name}*.`;
|
|
82
|
+
obj = obj[field];
|
|
83
|
+
if (typeof obj === 'undefined') return handleUndefined(name);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return obj;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function checkProperties(properties, obj, onError = name => throwError `Expect property *${name}*`, path = '') {
|
|
90
|
+
for (const name of Object.keys(properties)) {
|
|
91
|
+
const property = properties[name];
|
|
92
|
+
if (typeof property === 'object') {
|
|
93
|
+
checkProperties(property, obj[name] || {}, onError, path = `${path}${name}.`);
|
|
94
|
+
} else if (property) {
|
|
95
|
+
if (!obj[name]) onError(`${path}${name}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function mergeDeep(...objs) {
|
|
101
|
+
const target = {...objs[0]};
|
|
102
|
+
const obj = objs[1];
|
|
103
|
+
for (const name of Object.keys(obj)) {
|
|
104
|
+
if (name === '__proto__') continue;
|
|
105
|
+
const property = obj[name];
|
|
106
|
+
if (typeof property === 'object') {
|
|
107
|
+
if (target[name]) {
|
|
108
|
+
target[name] = mergeDeep(target[name], property);
|
|
109
|
+
} else {
|
|
110
|
+
delete property.__proto__;
|
|
111
|
+
target[name] = {...property};
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
target[name] = property;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (objs.length > 2) {
|
|
119
|
+
return mergeDeep(target, objs.slice(2));
|
|
120
|
+
} else {
|
|
121
|
+
return target;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function readFileIfExists(path, encoding) {
|
|
126
|
+
try {
|
|
127
|
+
return await fs.promises.readFile(path, encoding);
|
|
128
|
+
} catch(error) {
|
|
129
|
+
if (error.code === 'ENOENT' || error.code === 'EISDIR') return undefined;
|
|
130
|
+
else throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Takes path of md5 file as an argument and returns a JSON object containing hashes of files stored in MD5 file.
|
|
136
|
+
* @param {String} path
|
|
137
|
+
* @returns {JSON}
|
|
138
|
+
*/
|
|
139
|
+
async function parseMd5File(path) {
|
|
140
|
+
let md5Hashes = {};
|
|
141
|
+
const md5FileContent = await readFileIfExists(path);
|
|
142
|
+
if(md5FileContent == undefined) return md5Hashes;
|
|
143
|
+
let md5Checksums = md5FileContent.toString().split(os.EOL)
|
|
144
|
+
md5Checksums.forEach((checksum) => {
|
|
145
|
+
checksum = checksum.split(" ")
|
|
146
|
+
md5Hashes[checksum[1]] = checksum[0];
|
|
147
|
+
})
|
|
148
|
+
return md5Hashes;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Takes json object containing key as filename and value as MD5 hash and generates a md5sum format file.
|
|
153
|
+
* @param {String} path
|
|
154
|
+
* @param {JSON} data
|
|
155
|
+
*/
|
|
156
|
+
async function writeMd5File(path, data) {
|
|
157
|
+
let md5_output;
|
|
158
|
+
Object.keys(data).forEach(key => {
|
|
159
|
+
var currMd5 = `${data[key]} ${key}`;
|
|
160
|
+
if(md5_output == undefined)
|
|
161
|
+
md5_output = currMd5;
|
|
162
|
+
else
|
|
163
|
+
md5_output += os.EOL + currMd5;
|
|
164
|
+
})
|
|
165
|
+
await fs.promises.writeFile(path, md5_output);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = {
|
|
169
|
+
throwError,
|
|
170
|
+
resource,
|
|
171
|
+
cp,
|
|
172
|
+
format,
|
|
173
|
+
help,
|
|
174
|
+
checkDebug,
|
|
175
|
+
dirExists,
|
|
176
|
+
readFileIfExists,
|
|
177
|
+
globSingleFile,
|
|
178
|
+
getProperty,
|
|
179
|
+
checkProperties,
|
|
180
|
+
mergeDeep,
|
|
181
|
+
$,
|
|
182
|
+
exec,
|
|
183
|
+
execSync,
|
|
184
|
+
parseMd5File,
|
|
185
|
+
writeMd5File
|
|
186
|
+
}
|