[COMMON][ELASTIC] Uses new tpls for repos / images

This commit makes Elasticsearcg template to use the new generator for
repositories and images.

Issue-ID: OOM-2364
Signed-off-by: Sylvain Desbureaux <sylvain.desbureaux@orange.com>
Change-Id: I20c18632234c864ef2a29e3cfb259c9838a8c4d6
diff --git a/kubernetes/common/elasticsearch/Makefile b/kubernetes/common/elasticsearch/Makefile
new file mode 100644
index 0000000..4c79718
--- /dev/null
+++ b/kubernetes/common/elasticsearch/Makefile
@@ -0,0 +1,51 @@
+# Copyright © 2020 Samsung Electronics
+#
+# 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.
+
+ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+OUTPUT_DIR := $(ROOT_DIR)/../dist
+PACKAGE_DIR := $(OUTPUT_DIR)/packages
+SECRET_DIR := $(OUTPUT_DIR)/secrets
+
+EXCLUDES := dist resources templates charts docker
+HELM_BIN := helm
+HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.))))
+
+.PHONY: $(EXCLUDES) $(HELM_CHARTS)
+
+all: $(HELM_CHARTS)
+
+$(HELM_CHARTS):
+	@echo "\n[$@]"
+	@make package-$@
+
+make-%:
+	@if [ -f $*/Makefile ]; then make -C $*; fi
+
+dep-%: make-%
+	@if [ -f $*/requirements.yaml ]; then $(HELM_BIN) dep up $*; fi
+
+lint-%: dep-%
+	@if [ -f $*/Chart.yaml ]; then $(HELM_BIN) lint $*; fi
+
+package-%: lint-%
+	@mkdir -p $(PACKAGE_DIR)
+	@if [ -f $*/Chart.yaml ]; then $(HELM_BIN) package -d $(PACKAGE_DIR) $*; fi
+	@$(HELM_BIN) repo index $(PACKAGE_DIR)
+
+clean:
+	@rm -f */requirements.lock
+	@rm -f *tgz */charts/*tgz
+	@rm -rf $(PACKAGE_DIR)
+%:
+	@:
diff --git a/kubernetes/common/elasticsearch/components/Makefile b/kubernetes/common/elasticsearch/components/Makefile
new file mode 100644
index 0000000..f2e7a1f
--- /dev/null
+++ b/kubernetes/common/elasticsearch/components/Makefile
@@ -0,0 +1,51 @@
+# Copyright © 2020 Samsung Electronics
+#
+# 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.
+
+ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
+OUTPUT_DIR := $(ROOT_DIR)/../../dist
+PACKAGE_DIR := $(OUTPUT_DIR)/packages
+SECRET_DIR := $(OUTPUT_DIR)/secrets
+
+EXCLUDES := soHelpers
+HELM_BIN := helm
+HELM_CHARTS := soHelpers $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.))))
+
+.PHONY: $(EXCLUDES) $(HELM_CHARTS)
+
+all: $(HELM_CHARTS)
+
+$(HELM_CHARTS):
+	@echo "\n[$@]"
+	@make package-$@
+
+make-%:
+	@if [ -f $*/Makefile ]; then make -C $*; fi
+
+dep-%: make-%
+	@if [ -f $*/requirements.yaml ]; then $(HELM_BIN) dep up $*; fi
+
+lint-%: dep-%
+	@if [ -f $*/Chart.yaml ]; then $(HELM_BIN) lint $*; fi
+
+package-%: lint-%
+	@mkdir -p $(PACKAGE_DIR)
+	@if [ -f $*/Chart.yaml ]; then $(HELM_BIN) package -d $(PACKAGE_DIR) $*; fi
+	@$(HELM_BIN) repo index $(PACKAGE_DIR)
+
+clean:
+	@rm -f */requirements.lock
+	@rm -f *tgz */charts/*tgz
+	@rm -rf $(PACKAGE_DIR)
+%:
+	@:
diff --git a/kubernetes/common/elasticsearch/components/curator/hooks/job.install.yaml b/kubernetes/common/elasticsearch/components/curator/hooks/job.install.yaml
index 583c2d7..e1d6cba 100644
--- a/kubernetes/common/elasticsearch/components/curator/hooks/job.install.yaml
+++ b/kubernetes/common/elasticsearch/components/curator/hooks/job.install.yaml
@@ -47,7 +47,7 @@
 {{- end }}
       containers:
         - name: {{ template "common.fullname" . }}-curator
-          image: {{printf "%s/%s" (include "common.repository" .)  .Values.image }}
+          image: {{printf "%s/%s" (include "repositoryGenerator.repository" .)  .Values.image }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           volumeMounts:
             - name: config-volume
diff --git a/kubernetes/common/elasticsearch/components/curator/requirements.yaml b/kubernetes/common/elasticsearch/components/curator/requirements.yaml
index e9a5a5f..fbdf7b8 100644
--- a/kubernetes/common/elasticsearch/components/curator/requirements.yaml
+++ b/kubernetes/common/elasticsearch/components/curator/requirements.yaml
@@ -16,3 +16,6 @@
   - name: common
     version: ~6.x-0
     repository: 'file://../../../common'
+  - name: repositoryGenerator
+    version: ~6.x-0
+    repository: 'file://../../../repositoryGenerator'
diff --git a/kubernetes/common/elasticsearch/components/curator/templates/cronjob.yaml b/kubernetes/common/elasticsearch/components/curator/templates/cronjob.yaml
index b9e2c05..ff63cf0 100644
--- a/kubernetes/common/elasticsearch/components/curator/templates/cronjob.yaml
+++ b/kubernetes/common/elasticsearch/components/curator/templates/cronjob.yaml
@@ -76,7 +76,7 @@
           {{- end }}
           containers:
             - name: {{ template "common.fullname" . }}-curator
-              image: {{printf "%s/%s" (include "common.repository" .)  .Values.image }}
+              image: {{printf "%s/%s" (include "repositoryGenerator.repository" .)  .Values.image }}
               imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
               volumeMounts:
                 - name: config-volume
diff --git a/kubernetes/common/elasticsearch/components/curator/values.yaml b/kubernetes/common/elasticsearch/components/curator/values.yaml
index addd528..62964ff 100644
--- a/kubernetes/common/elasticsearch/components/curator/values.yaml
+++ b/kubernetes/common/elasticsearch/components/curator/values.yaml
@@ -22,7 +22,7 @@
       mountPath: /dockerdata-nfs/backup
     storageClass:
   clusterName: cluster.local
-repositoryOverride: docker.io
+
 #################################################################
 # Application configuration defaults.
 #################################################################
diff --git a/kubernetes/common/elasticsearch/components/data/requirements.yaml b/kubernetes/common/elasticsearch/components/data/requirements.yaml
index a1f72ff..ba64f96 100644
--- a/kubernetes/common/elasticsearch/components/data/requirements.yaml
+++ b/kubernetes/common/elasticsearch/components/data/requirements.yaml
@@ -16,3 +16,6 @@
   - name: common
     version: ~6.x-0
     repository: 'file://../../../common'
+  - name: repositoryGenerator
+    version: ~6.x-0
+    repository: 'file://../../../repositoryGenerator'
diff --git a/kubernetes/common/elasticsearch/components/data/templates/statefulset.yaml b/kubernetes/common/elasticsearch/components/data/templates/statefulset.yaml
index 98d533d..ea805c1 100644
--- a/kubernetes/common/elasticsearch/components/data/templates/statefulset.yaml
+++ b/kubernetes/common/elasticsearch/components/data/templates/statefulset.yaml
@@ -17,7 +17,7 @@
 kind: StatefulSet
 {{ $role := "data" -}}
 {{ $suffix := $role -}}
-{{ $labels := (dict "role" $role "discovery" (include "elasticsearch.clustername" .)) -}}
+{{ $labels := (dict "role" $role "discovery" .Values.cluster_name) -}}
 metadata: {{- include "common.resourceMetadata" (dict "suffix" $suffix "labels" $labels "dot" . )| nindent 2 }}
 spec:
   updateStrategy:
@@ -34,7 +34,8 @@
   template:
     metadata: {{- include "common.templateMetadata" (dict "labels" $labels "dot" .) | nindent 6 }}
     spec:
-{{- include "elasticsearch.imagePullSecrets" . | nindent 6 }}
+      imagePullSecrets:
+      - name: "{{ include "common.namespace" . }}-docker-registry-key"
       {{- if .Values.affinity }}
       affinity: {{- include "common.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
       {{- end }}
@@ -44,7 +45,6 @@
       {{- if .Values.tolerations }}
       tolerations: {{- include "common.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
       {{- end }}
-      serviceAccountName: {{ template "elasticsearch.data.serviceAccountName" . }}
       {{- if .Values.securityContext.enabled }}
       securityContext:
         fsGroup: {{ .Values.securityContext.fsGroup }}
@@ -54,7 +54,7 @@
         {{- if .Values.sysctlImage.enabled }}
         ## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
         - name: sysctl
-          image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
+          image: {{ include "repositoryGenerator.image.busybox" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           command:
             - /bin/sh
@@ -69,7 +69,7 @@
         {{- end }}
         {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
         - name: volume-permissions
-          image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
+          image: {{ include "repositoryGenerator.image.busybox" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           command:
             - /bin/sh
@@ -88,7 +88,7 @@
       {{- end }}
       containers:
         - name: {{ include "common.name" . }}-data
-          image: {{ printf "%s/%s" (include "common.repository" .)  .Values.image }}
+          image: {{ printf "%s/%s" (include "repositoryGenerator.dockerHubRepository" .)  .Values.image }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           {{- if .Values.securityContext.enabled }}
           securityContext:
@@ -98,7 +98,7 @@
             - name: BITNAMI_DEBUG
               value: {{ ternary "true" "false" .Values.debug | quote }}
             - name: ELASTICSEARCH_CLUSTER_NAME
-              value: {{include "elasticsearch.clustername" .}}
+              value: {{ .Values.cluster_name }}
             - name: ELASTICSEARCH_CLUSTER_HOSTS
               value: {{ include "common.name" . }}-discovery
             {{- if .Values.plugins }}
diff --git a/kubernetes/common/elasticsearch/components/data/values.yaml b/kubernetes/common/elasticsearch/components/data/values.yaml
index 8b5e687..1328a20 100644
--- a/kubernetes/common/elasticsearch/components/data/values.yaml
+++ b/kubernetes/common/elasticsearch/components/data/values.yaml
@@ -22,10 +22,13 @@
     backup:
       mountPath: /dockerdata-nfs/backup
     storageClass:
-repositoryOverride: docker.io
+
 #################################################################
 # Application configuration defaults.
 #################################################################
+
+cluster_name: onap
+
 ## Init containers parameters:
 sysctlImage:
   enabled: true
diff --git a/kubernetes/common/elasticsearch/components/master/requirements.yaml b/kubernetes/common/elasticsearch/components/master/requirements.yaml
index a1f72ff..ba64f96 100644
--- a/kubernetes/common/elasticsearch/components/master/requirements.yaml
+++ b/kubernetes/common/elasticsearch/components/master/requirements.yaml
@@ -16,3 +16,6 @@
   - name: common
     version: ~6.x-0
     repository: 'file://../../../common'
+  - name: repositoryGenerator
+    version: ~6.x-0
+    repository: 'file://../../../repositoryGenerator'
diff --git a/kubernetes/common/elasticsearch/components/master/templates/statefulset.yaml b/kubernetes/common/elasticsearch/components/master/templates/statefulset.yaml
index 6744f75..a35b4bf 100644
--- a/kubernetes/common/elasticsearch/components/master/templates/statefulset.yaml
+++ b/kubernetes/common/elasticsearch/components/master/templates/statefulset.yaml
@@ -18,7 +18,7 @@
 kind: StatefulSet
 {{ $role := "master" -}}
 {{ $suffix := $role -}}
-{{ $labels := (dict "role" $role "discovery" (include "elasticsearch.clustername" .)) -}}
+{{ $labels := (dict "role" $role "discovery" .Values.cluster_name) -}}
 metadata: {{- include "common.resourceMetadata" (dict "suffix" $suffix "labels" $labels "dot" . )| nindent 2 }}
 spec:
   updateStrategy:
@@ -32,7 +32,8 @@
   template:
     metadata: {{- include "common.templateMetadata" (dict "labels" $labels "dot" .) | nindent 6 }}
     spec:
-{{- include "elasticsearch.imagePullSecrets" . | nindent 6 }}
+      imagePullSecrets:
+      - name: "{{ include "common.namespace" . }}-docker-registry-key"
       {{- if .Values.affinity }}
       affinity: {{- include "common.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
       {{- end }}
@@ -42,7 +43,6 @@
       {{- if .Values.tolerations }}
       tolerations: {{- include "common.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
       {{- end }}
-      serviceAccountName: {{ template "elasticsearch.serviceAccountName" . }}
       {{- if .Values.securityContext.enabled }}
       securityContext:
         fsGroup: {{ .Values.securityContext.fsGroup }}
@@ -52,7 +52,7 @@
         {{- if .Values.sysctlImage.enabled }}
         ## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
         - name: sysctl
-          image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
+          image: {{ include "repositoryGenerator.image.busybox" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           command:
             - /bin/sh
@@ -67,7 +67,7 @@
         {{- end }}
         {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
         - name: volume-permissions
-          image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
+          image: {{ include "repositoryGenerator.image.busybox" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           command:
             - /bin/sh
@@ -86,7 +86,7 @@
       {{- end }}
       containers:
         - name: {{ include "common.name" . }}-master
-          image: {{ printf "%s/%s" (include "common.repository" .)  .Values.image }}
+          image: {{ printf "%s/%s" (include "repositoryGenerator.dockerHubRepository" .)  .Values.image }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           {{- if .Values.securityContext.enabled }}
           securityContext:
@@ -96,7 +96,7 @@
             - name: BITNAMI_DEBUG
               value: {{ ternary "true" "false" .Values.debug | quote }}
             - name: ELASTICSEARCH_CLUSTER_NAME
-              value: {{ include "elasticsearch.clustername" . }}
+              value: {{ .Values.cluster_name }}
             - name: ELASTICSEARCH_CLUSTER_HOSTS
               value: {{ include "common.name" . }}-discovery
             - name: ELASTICSEARCH_CLUSTER_MASTER_HOSTS
diff --git a/kubernetes/common/elasticsearch/components/master/values.yaml b/kubernetes/common/elasticsearch/components/master/values.yaml
index 4095bd3..3380449 100644
--- a/kubernetes/common/elasticsearch/components/master/values.yaml
+++ b/kubernetes/common/elasticsearch/components/master/values.yaml
@@ -22,10 +22,13 @@
     backup:
       mountPath: /dockerdata-nfs/backup
     storageClass:
-repositoryOverride: docker.io
+
 #################################################################
 # Application configuration defaults.
 #################################################################
+
+cluster_name: onap
+
 ## Init containers parameters:
 sysctlImage:
   enabled: true
diff --git a/kubernetes/common/elasticsearch/requirements.yaml b/kubernetes/common/elasticsearch/requirements.yaml
index 5900f41..4b7e88f 100644
--- a/kubernetes/common/elasticsearch/requirements.yaml
+++ b/kubernetes/common/elasticsearch/requirements.yaml
@@ -30,3 +30,6 @@
   - name: certInitializer
     version: ~6.x-0
     repository: 'file://../certInitializer'
+  - name: repositoryGenerator
+    version: ~6.x-0
+    repository: 'file://../repositoryGenerator'
diff --git a/kubernetes/common/elasticsearch/templates/_helpers.tpl b/kubernetes/common/elasticsearch/templates/_helpers.tpl
index 6e745bd..1de2599 100644
--- a/kubernetes/common/elasticsearch/templates/_helpers.tpl
+++ b/kubernetes/common/elasticsearch/templates/_helpers.tpl
@@ -71,35 +71,3 @@
 {{- end -}}
 
 
-{{/*
-Return the proper Docker Image Registry Secret Names
-*/}}
-{{- define "elasticsearch.imagePullSecrets" -}}
-{{- if .Values.global }}
-{{- if .Values.global.imagePullSecrets }}
-imagePullSecrets:
-{{- range .Values.global.imagePullSecrets }}
-  - name: {{ . }}
-{{- end }}
-{{- end }}
-{{- else }}
-{{- $imagePullSecrets := coalesce .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.curator.image.pullSecrets .Values.sysctlImage.pullSecrets .Values.volumePermissions.image.pullSecrets -}}
-{{- if $imagePullSecrets }}
-imagePullSecrets:
-{{- range $imagePullSecrets }}
-  - name: {{ . }}
-{{- end -}}
-{{- end -}}
-{{- end -}}
-{{- end -}}
-
-{{/*
-Create the name of the service account to use
-*/}}
-{{- define "elasticsearch.curator.serviceAccountName" -}}
-{{- if .Values.curator.serviceAccount.create -}}
-    {{ default (include "common.fullname" (dict "suffix" "currator" "dot" .)) .Values.curator.serviceAccount.name }}
-{{- else -}}
-    {{ default "default" .Values.curator.serviceAccount.name }}
-{{- end -}}
-{{- end -}}
diff --git a/kubernetes/common/elasticsearch/templates/coordinating-deploy.yaml b/kubernetes/common/elasticsearch/templates/coordinating-deploy.yaml
index cf9ef73..22de4db 100644
--- a/kubernetes/common/elasticsearch/templates/coordinating-deploy.yaml
+++ b/kubernetes/common/elasticsearch/templates/coordinating-deploy.yaml
@@ -30,7 +30,8 @@
   template:
     metadata: {{- include "common.templateMetadata" (dict "labels" $labels "dot" .) | nindent 6 }}
     spec:
-{{- include "elasticsearch.imagePullSecrets" . | nindent 6 }}
+      imagePullSecrets:
+      - name: "{{ include "common.namespace" . }}-docker-registry-key"
       {{- if .Values.affinity }}
       affinity: {{- include "common.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
       {{- end }}
@@ -50,7 +51,7 @@
       initContainers:
       {{- if .Values.sysctlImage.enabled }}
         - name: sysctl
-          image: {{ .Values.global.busyboxRepository | default .Values.busyboxRepository }}/{{ .Values.global.busyboxImage | default .Values.busyboxImage }}
+          image: {{ include "repositoryGenerator.image.busybox" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           command:
             - /bin/sh
@@ -67,7 +68,7 @@
 
       containers:
         - name: {{ include "common.name" . }}-nginx
-          image: {{printf "%s/%s:%s" (include "common.repository" .)  .Values.nginx.imageName  .Values.nginx.tag }}
+          image: {{ include "repositoryGenerator.image.nginx" . }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.nginx.pullPolicy | quote }}
           ports: {{- include "common.containerPorts" . | indent 12 -}}
           {{- if .Values.nginx.livenessProbe }}
@@ -87,7 +88,7 @@
           {{- include "common.certInitializer.volumeMount" . | nindent 10 }}
 
         - name: {{ include "common.name" . }}-elasticsearch
-          image: {{ printf "%s/%s" (include "common.repository" .)  .Values.image }}
+          image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
           {{- if .Values.securityContext.enabled }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
           securityContext:
diff --git a/kubernetes/common/elasticsearch/values.yaml b/kubernetes/common/elasticsearch/values.yaml
index 7722af9..b91ac76 100644
--- a/kubernetes/common/elasticsearch/values.yaml
+++ b/kubernetes/common/elasticsearch/values.yaml
@@ -19,11 +19,6 @@
 global:
   aafEnabled: true
   nodePortPrefix: 302
-  readinessImage: onap/oom/readiness:3.0.1
-  loggingRepository: docker.elastic.co
-  loggingImage: beats/filebeat:5.5.0
-  busyboxRepository: docker.io
-  busyboxImage: library/busybox:latest
   clusterName: cluster.local
 
 persistence:
@@ -31,7 +26,6 @@
   backup:
     mountPath: /dockerdata-nfs/backup
   storageClass:
-repositoryOverride: docker.io
 
 #################################################################
 # Application configuration defaults.
@@ -134,13 +128,8 @@
   ##
   # name:
 
-## Bitnami Minideb image version
-## ref: https://hub.docker.com/r/bitnami/minideb/tags/
-##
 sysctlImage:
   enabled: true
-  imageName: bitnami/minideb
-  tag: stretch
   ## Specify a imagePullPolicy
   ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
   ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
@@ -155,8 +144,6 @@
 
 # nginx image
 nginx:
-  imageName: bitnami/nginx
-  tag: 1.16-debian-9
   pullPolicy: IfNotPresent
   service:
     name: nginx
@@ -318,7 +305,9 @@
   # dedicatednode: "no"
   # handles master and data node functionality
   dedicatednode: "no"
+  cluster_name: elasticsearch
 data:
   enabled: false
+  cluster_name: elasticsearch
 curator:
   enabled: false