From d74a9f34b0342878644f8421a3a0f77e2666387d Mon Sep 17 00:00:00 2001
From: Vladyslav Hundarchuk <vladyslav_hundarchuk@epam.com>
Date: Tue, 10 Jan 2023 14:47:20 +0000
Subject: [PATCH] Modify files for merging all helms register service

---
 .gitlab-ci.yml                                |  3 +
 devops/gcp/configmap/Chart.yaml               | 24 ------
 devops/gcp/configmap/README.md                | 81 -------------------
 .../templates/register-variables.yml          | 25 ------
 devops/gcp/configmap/values.yaml              | 25 ------
 devops/gcp/deploy/README.md                   | 58 +++++++++----
 .../gcp/deploy/templates/register-deploy.yml  | 36 ++++-----
 .../templates/register-service-account.yml    |  4 +-
 .../gcp/deploy/templates/register-service.yml | 10 +--
 .../deploy/templates/register-variables.yml   | 25 ++++++
 .../templates/register-virtual-service.yml    |  6 +-
 devops/gcp/deploy/values.yaml                 | 15 ++++
 12 files changed, 113 insertions(+), 199 deletions(-)
 delete mode 100644 devops/gcp/configmap/Chart.yaml
 delete mode 100644 devops/gcp/configmap/README.md
 delete mode 100644 devops/gcp/configmap/templates/register-variables.yml
 delete mode 100644 devops/gcp/configmap/values.yaml
 create mode 100644 devops/gcp/deploy/templates/register-variables.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7b7c1bc77..8d9495b53 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -18,6 +18,9 @@ variables:
   AZURE_TEST_SUBDIR: testing/register-test-azure
   AZURE_SWAGGER_PATH: api/register/v1/swagger-ui/index.html#/
 
+  # FIXME remove when all services are migrated to a single helm
+  OSDU_GCP_ENABLE_HELM_CONFIG: "false"
+
 include:
   - project: "osdu/platform/ci-cd-pipelines"
     file: "standard-setup.yml"
diff --git a/devops/gcp/configmap/Chart.yaml b/devops/gcp/configmap/Chart.yaml
deleted file mode 100644
index f1bd988dd..000000000
--- a/devops/gcp/configmap/Chart.yaml
+++ /dev/null
@@ -1,24 +0,0 @@
-apiVersion: v2
-name: gcp-register-configmap
-description: A Helm chart for Kubernetes
-
-# A chart can be either an 'application' or a 'library' chart.
-#
-# Application charts are a collection of templates that can be packaged into versioned archives
-# to be deployed.
-#
-# Library charts provide useful utilities or functions for the chart developer. They're included as
-# a dependency of application charts to inject those utilities and functions into the rendering
-# pipeline. Library charts do not define any templates and therefore cannot be deployed.
-type: application
-
-# This is the chart version. This version number should be incremented each time you make changes
-# to the chart and its templates, including the app version.
-# Versions are expected to follow Semantic Versioning (https://semver.org/)
-version: 0.1.0
-
-# This is the version number of the application being deployed. This version number should be
-# incremented each time you make changes to the application. Versions are not expected to
-# follow Semantic Versioning. They should reflect the version the application is using.
-# It is recommended to use it with quotes.
-appVersion: "1.16.0"
diff --git a/devops/gcp/configmap/README.md b/devops/gcp/configmap/README.md
deleted file mode 100644
index 9b020b2bc..000000000
--- a/devops/gcp/configmap/README.md
+++ /dev/null
@@ -1,81 +0,0 @@
-<!--- Configmap -->
-
-# Configmap helm chart
-
-## Introduction
-
-This chart bootstraps a configmap deployment on a [Kubernetes](https://kubernetes.io) cluster using [Helm](https://helm.sh) package manager.
-
-## Prerequisites
-
-The code was tested on **Kubernetes cluster** (v1.21.11) with **Istio** (1.12.6)
-> It is possible to use other versions, but it hasn't been tested
-
-### Operation system
-
-The code works in Debian-based Linux (Debian 10 and Ubuntu 20.04) and Windows WSL 2. Also, it works but is not guaranteed in Google Cloud Shell. All other operating systems, including macOS, are not verified and supported.
-
-### Packages
-
-Packages are only needed for installation from a local computer.
-
-- **HELM** (version: v3.7.1 or higher) [helm](https://helm.sh/docs/intro/install/)
-- **Kubectl** (version: v1.21.0 or higher) [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
-
-## Installation
-
-First you need to set variables in **values.yaml** file using any code editor. Some of the values are prefilled, but you need to specify some values as well. You can find more information about them below.
-
-### Common variables
-
-| Name | Description | Type | Default |Required |
-|------|-------------|------|---------|---------|
-**logLevel** | logging level | string | INFO | yes
-**springProfilesActive** | active spring profile | string | gcp | yes
-
-### Google Cloud variables
-
-| Name | Description | Type | Default |Required |
-|------|-------------|------|---------|---------|
-**googleCloudProject** | your Google Cloud cloud project | string | -| yes
-**googleAudiences** | your Google Cloud client ID | string | - | yes
-**entitlementsHost** | Entitlements host | string | "http://entitlements" | yes
-**partitionHost** | Partition host | string | "http://partition" | yes
-**recordsChangedPubsubEndpoint** | Endpoint to PubSub topic | string | - | yes
-**storageHost** | Storage host | string | "http://storage" | yes
-**serviceIdentity** | Service account in Google Cloud fo PubSub | string | "register-pubsub-identity" | yes
-**keyRing** | Type of keys | string | "csqp" | yes
-**kmsKey** | Key management service key (must be replaced during installation) | string | "registerService" | yes
-**subscriberPrivateKeyId** | Subscriber test private key id (must be replaced during installation) | string | "testkey" | yes
-
-### Config variables
-
-| Name | Description | Type | Default |Required |
-|------|-------------|------|---------|---------|
-**configmap** | configmap to be used | string | register-config | yes
-**appName** | name of the app | string | register | yes
-**onPremEnabled** | whether on-prem is enabled | boolean | false | yes
-
-### Install the helm chart
-
-Run this command from within this directory:
-
-```console
-helm install gcp-register-configmap .
-```
-
-## Uninstalling the Chart
-
-To uninstall the helm deployment:
-
-```console
-helm uninstall gcp-register-configmap
-```
-
-To delete secrets and PVCs:
-
-```console
-kubectl delete secret --all; kubectl delete pvc --all
-```
-
-[Move-to-Top](#configmap-helm-chart)
diff --git a/devops/gcp/configmap/templates/register-variables.yml b/devops/gcp/configmap/templates/register-variables.yml
deleted file mode 100644
index 110321dca..000000000
--- a/devops/gcp/configmap/templates/register-variables.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-apiVersion: v1
-kind: ConfigMap
-metadata:
-  labels:
-    app: "{{ .Values.conf.appName }}"
-  name: "{{ .Values.conf.configmap }}"
-  namespace: "{{ .Release.Namespace }}"
-data:
-  LOG_LEVEL: "{{ .Values.data.logLevel }}"
-  SPRING_PROFILES_ACTIVE: "{{ .Values.data.springProfilesActive }}"
-  SUBSCRIBER_PRIVATE_KEY_ID: "{{ .Values.data.subscriberPrivateKeyId }}"
-  {{- if .Values.conf.cicdEnabled }}
-  INTEGRATION_TEST_AUDIENCES: "{{.Values.data.googleAudiences}}"
-  {{- end }}
-  {{- if not .Values.conf.onPremEnabled }}
-  GOOGLE_CLOUD_PROJECT: "{{ .Values.data.googleCloudProject }}"
-  GOOGLE_AUDIENCES: "{{ .Values.data.googleAudiences }}"
-  ENTITLEMENTS_HOST: "{{ .Values.data.entitlementsHost }}"
-  RECORDS_CHANGE_PUBSUB_ENDPOINT: "{{ .Values.data.recordsChangePubsubEndpoint }}"
-  PARTITION_HOST: "{{ .Values.data.partitionHost }}"
-  STORAGE_HOST: "{{ .Values.data.storageHost }}"
-  SERVICE_IDENTITY: "{{ .Values.data.serviceIdentity }}"
-  KEY_RING: "{{ .Values.data.keyRing }}"
-  KMS_KEY: "{{ .Values.data.kmsKey }}"
-  {{- end }}
diff --git a/devops/gcp/configmap/values.yaml b/devops/gcp/configmap/values.yaml
deleted file mode 100644
index 3e5f5c578..000000000
--- a/devops/gcp/configmap/values.yaml
+++ /dev/null
@@ -1,25 +0,0 @@
-# Default values for register-configmap.
-# This is a YAML-formatted file.
-# Declare variables to be passed into your templates.
-
-data:
-  # common
-  logLevel: "ERROR"
-  springProfilesActive: "gcp"
-  # gcp
-  googleCloudProject: ""
-  googleAudiences: ""
-  entitlementsHost: "http://entitlements"
-  partitionHost: "http://partition"
-  recordsChangedPubsubEndpoint: ""
-  storageHost: "http://storage"
-  serviceIdentity: "register-pubsub-identity"
-  keyRing: "csqp"
-  kmsKey: "registerService"
-  subscriberPrivateKeyId: "testkey"
-
-conf:
-  configmap: "register-config"
-  appName: "register"
-  onPremEnabled: false
-  cicdEnabled: false
diff --git a/devops/gcp/deploy/README.md b/devops/gcp/deploy/README.md
index 44bb77bc7..ebc9e8ebf 100644
--- a/devops/gcp/deploy/README.md
+++ b/devops/gcp/deploy/README.md
@@ -27,30 +27,56 @@ Packages are only needed for installation from a local computer.
 
 First you need to set variables in **values.yaml** file using any code editor. Some of the values are prefilled, but you need to specify some values as well. You can find more information about them below.
 
-### Common variables
+### Configmap variables
 
 | Name | Description | Type | Default |Required |
 |------|-------------|------|---------|---------|
-**image** | your image name | string | - | yes
-**requestsCpu** | amount of requests CPU | string | 0.1 | yes
-**requestsMemory** | amount of requests memory| string | 384M | yes
-**limitsCpu** | CPU limit | string | 1 | yes
-**limitsMemory** | memory limit | string | 1G | yes
-**serviceAccountName** | name of your service account | string | register | yes
-**imagePullPolicy** | when to pull image | string | IfNotPresent | yes
+**data.logLevel** | logging level | string | INFO | yes
+**data.springProfilesActive** | active spring profile | string | gcp | yes
+**data.googleCloudProject** | your Google Cloud cloud project | string | -| yes
+**data.googleAudiences** | your Google Cloud client ID | string | - | yes
+**data.entitlementsHost** | Entitlements host | string | "http://entitlements" | yes
+**data.partitionHost** | Partition host | string | "http://partition" | yes
+**data.recordsChangedPubsubEndpoint** | Endpoint to PubSub topic | string | - | yes
+**data.storageHost** | Storage host | string | "http://storage" | yes
+**data.serviceIdentity** | Service account in Google Cloud fo PubSub | string | "register-pubsub-identity" | yes
+**data.keyRing** | Type of keys | string | "csqp" | yes
+**data.kmsKey** | Key management service key (must be replaced during installation) | string | "registerService" | yes
+**data.subscriberPrivateKeyId** | Subscriber test private key id (must be replaced during installation) | string | "testkey" | yes
+
+### Deployment variables
+
+| Name | Description | Type | Default |Required |
+|------|-------------|------|---------|---------|
+**data.image** | your image name | string | - | yes
+**data.requestsCpu** | amount of requests CPU | string | 0.1 | yes
+**data.requestsMemory** | amount of requests memory| string | 384M | yes
+**data.limitsCpu** | CPU limit | string | 1 | yes
+**data.limitsMemory** | memory limit | string | 1G | yes
+**data.serviceAccountName** | name of your service account | string | register | yes
+**data.imagePullPolicy** | when to pull image | string | IfNotPresent | yes
 
 ### Config variables
 
 | Name | Description | Type | Default |Required |
 |------|-------------|------|---------|---------|
-**appName** | name of the app | string | register | yes
-**configmap** | configmap to be used | string | register-config | yes
-**registerPostgresSecretName** | secret for postgres | string | register-postgres-secret | yes
-**registerKeycloakSecretName** | secret for keycloak | string | register-keycloak-secret | yes
-**registerKmsSecretName** | secret for kms | string |  "register-kms-secret" | yes
-**rabbitmqSecretName** | secret for rabbitmq | string | rabbitmq-secret | yes
-**onPremEnabled** | whether on-prem is enabled | boolean | false | yes
-**domain** | your domain | string | - | yes
+**conf.appName** | name of the app | string | register | yes
+**conf.configmap** | configmap to be used | string | register-config | yes
+**conf.registerPostgresSecretName** | secret for postgres | string | register-postgres-secret | yes
+**conf.registerKeycloakSecretName** | secret for keycloak | string | register-keycloak-secret | yes
+**conf.registerKmsSecretName** | secret for kms | string |  "register-kms-secret" | yes
+**conf.rabbitmqSecretName** | secret for rabbitmq | string | rabbitmq-secret | yes
+**conf.onPremEnabled** | whether on-prem is enabled | boolean | false | yes
+**conf.domain** | your domain | string | - | yes
+
+### ISTIO variables
+
+| Name | Description | Type | Default |Required |
+|------|-------------|------|---------|---------|
+**istio.proxyCPU** | CPU request for Envoy sidecars | string | 50m | yes
+**istio.proxyCPULimit** | CPU limit for Envoy sidecars | string | 500m | yes
+**istio.proxyMemory** | memory request for Envoy sidecars | string | 64Mi | yes
+**istio.proxyMemoryLimit** | memory limit for Envoy sidecars | string | 512Mi | yes
 
 ### Install the helm chart
 
diff --git a/devops/gcp/deploy/templates/register-deploy.yml b/devops/gcp/deploy/templates/register-deploy.yml
index 28aee193c..7d8363484 100644
--- a/devops/gcp/deploy/templates/register-deploy.yml
+++ b/devops/gcp/deploy/templates/register-deploy.yml
@@ -2,18 +2,18 @@ apiVersion: apps/v1
 kind: Deployment
 metadata:
   labels:
-    app: "{{ .Values.conf.appName }}"
-  name: "{{ .Values.conf.appName }}"
-  namespace: "{{ .Release.Namespace }}"
+    app: {{ .Values.conf.appName | quote }}
+  name: {{ .Values.conf.appName | quote }}
+  namespace: {{ .Release.Namespace | quote }}
 spec:
   selector:
     matchLabels:
-      app: "{{ .Values.conf.appName }}"
+      app: {{ .Values.conf.appName | quote }}
   replicas: 1
   template:
     metadata:
       labels:
-        app: "{{ .Values.conf.appName }}"
+        app: {{ .Values.conf.appName | quote }}
       annotations:
         rollme: {{ randAlphaNum 5 | quote }}
         sidecar.istio.io/proxyCPU: {{ .Values.istio.proxyCPU | quote }}
@@ -22,21 +22,21 @@ spec:
         sidecar.istio.io/proxyMemoryLimit: {{ .Values.istio.proxyMemoryLimit | quote }}
     spec:
       containers:
-      - name: "{{ .Values.conf.appName }}"
-        image: "{{ .Values.data.image }}"
-        imagePullPolicy: "{{ .Values.data.imagePullPolicy }}"
+      - name: {{ .Values.conf.appName | quote }}
+        image: {{ .Values.data.image | quote }}
+        imagePullPolicy: {{ .Values.data.imagePullPolicy | quote }}
         envFrom:
         - configMapRef:
-            name: "{{ .Values.conf.configmap }}"
+            name: {{ .Values.conf.configmap | quote }}
         {{- if .Values.conf.onPremEnabled }}
         - secretRef:
-            name: "{{ .Values.conf.rabbitmqSecretName }}"
+            name: {{ .Values.conf.rabbitmqSecretName | quote }}
         - secretRef:
-            name: "{{ .Values.conf.registerPostgresSecretName }}"
+            name: {{ .Values.conf.registerPostgresSecretName | quote }}
         - secretRef:
-            name: "{{ .Values.conf.registerKeycloakSecretName }}"
+            name: {{ .Values.conf.registerKeycloakSecretName | quote }}
         - secretRef:
-            name: "{{ .Values.conf.registerKmsSecretName }}"
+            name: {{ .Values.conf.registerKmsSecretName | quote }}
         {{- end }}
         securityContext:
           allowPrivilegeEscalation: false
@@ -45,9 +45,9 @@ spec:
         - containerPort: 8080
         resources:
           requests:
-            cpu: "{{ .Values.data.requestsCpu }}"
-            memory: "{{ .Values.data.requestsMemory }}"
+            cpu: {{ .Values.data.requestsCpu | quote }}
+            memory: {{ .Values.data.requestsMemory | quote }}
           limits:
-            cpu: "{{ .Values.data.limitsCpu }}"
-            memory: "{{ .Values.data.limitsMemory }}"
-      serviceAccountName: "{{ .Values.data.serviceAccountName }}"
+            cpu: {{ .Values.data.limitsCpu | quote }}
+            memory: {{ .Values.data.limitsMemory | quote }}
+      serviceAccountName: {{ .Values.data.serviceAccountName | quote }}
diff --git a/devops/gcp/deploy/templates/register-service-account.yml b/devops/gcp/deploy/templates/register-service-account.yml
index 25fd74efb..f0771985c 100644
--- a/devops/gcp/deploy/templates/register-service-account.yml
+++ b/devops/gcp/deploy/templates/register-service-account.yml
@@ -2,6 +2,6 @@
 apiVersion: v1
 kind: ServiceAccount
 metadata:
-  name: "{{ .Values.data.serviceAccountName }}"
-  namespace: "{{ .Release.Namespace }}"
+  name: {{ .Values.data.serviceAccountName | quote }}
+  namespace: {{ .Release.Namespace | quote }}
 {{- end }}
diff --git a/devops/gcp/deploy/templates/register-service.yml b/devops/gcp/deploy/templates/register-service.yml
index 2f158ffe0..6535489d6 100644
--- a/devops/gcp/deploy/templates/register-service.yml
+++ b/devops/gcp/deploy/templates/register-service.yml
@@ -1,15 +1,15 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: "{{ .Values.conf.appName }}"
+  name: {{ .Values.conf.appName | quote }}
   annotations:
     {{- if not .Values.conf.onPremEnabled }}
     cloud.google.com/neg: '{"ingress": true}'
     {{- end }}
-  namespace: "{{ .Release.Namespace }}"
+  namespace: {{ .Release.Namespace | quote }}
   labels:
-    app: "{{ .Values.conf.appName }}"
-    service: "{{ .Values.conf.appName }}"
+    app: {{ .Values.conf.appName | quote }}
+    service: {{ .Values.conf.appName | quote }}
 spec:
   ports:
     - protocol: TCP
@@ -17,4 +17,4 @@ spec:
       targetPort: 8080
       name: http
   selector:
-    app: "{{ .Values.conf.appName }}"
+    app: {{ .Values.conf.appName | quote }}
diff --git a/devops/gcp/deploy/templates/register-variables.yml b/devops/gcp/deploy/templates/register-variables.yml
new file mode 100644
index 000000000..a948126ec
--- /dev/null
+++ b/devops/gcp/deploy/templates/register-variables.yml
@@ -0,0 +1,25 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  labels:
+    app: {{ .Values.conf.appName | quote }}
+  name: {{ .Values.conf.configmap | quote }}
+  namespace: {{ .Release.Namespace | quote }}
+data:
+  LOG_LEVEL: {{ .Values.data.logLevel | quote }}
+  SPRING_PROFILES_ACTIVE: {{ .Values.data.springProfilesActive | quote }}
+  SUBSCRIBER_PRIVATE_KEY_ID: {{ .Values.data.subscriberPrivateKeyId | quote }}
+  {{- if .Values.conf.cicdEnabled }}
+  INTEGRATION_TEST_AUDIENCES: {{.Values.data.googleAudiences  | quote }}
+  {{- end }}
+  {{- if not .Values.conf.onPremEnabled }}
+  GOOGLE_CLOUD_PROJECT: {{ .Values.data.googleCloudProject  | quote }}
+  GOOGLE_AUDIENCES: {{ .Values.data.googleAudiences  | quote }}
+  ENTITLEMENTS_HOST: {{ .Values.data.entitlementsHost  | quote }}
+  RECORDS_CHANGE_PUBSUB_ENDPOINT: "{{ .Values.data.recordsChangePubsubEndpoint}}"
+  PARTITION_HOST: {{ .Values.data.partitionHost  | quote }}
+  STORAGE_HOST: {{ .Values.data.storageHost  | quote }}
+  SERVICE_IDENTITY: {{ .Values.data.serviceIdentity  | quote }}
+  KEY_RING: {{ .Values.data.keyRing  | quote}}
+  KMS_KEY: {{ .Values.data.kmsKey  | quote }}
+  {{- end }}
diff --git a/devops/gcp/deploy/templates/register-virtual-service.yml b/devops/gcp/deploy/templates/register-virtual-service.yml
index 56d685621..6b6167201 100644
--- a/devops/gcp/deploy/templates/register-virtual-service.yml
+++ b/devops/gcp/deploy/templates/register-virtual-service.yml
@@ -1,8 +1,8 @@
 apiVersion: networking.istio.io/v1alpha3
 kind: VirtualService
 metadata:
-  name: "{{ .Values.conf.appName }}"
-  namespace: "{{ .Release.Namespace }}"
+  name: {{ .Values.conf.appName | quote }}
+  namespace: {{ .Release.Namespace | quote }}
 spec:
   hosts:
     {{- if and .Values.conf.domain .Values.conf.onPremEnabled }}
@@ -22,4 +22,4 @@ spec:
         - destination:
             port:
               number: 80
-            host: "{{ .Values.conf.appName }}.{{ .Release.Namespace }}.svc.cluster.local"
+            host: {{printf "%s.%s.svc.cluster.local" .Values.conf.appName .Release.Namespace | quote }}
diff --git a/devops/gcp/deploy/values.yaml b/devops/gcp/deploy/values.yaml
index 2058aecce..3820d40fd 100644
--- a/devops/gcp/deploy/values.yaml
+++ b/devops/gcp/deploy/values.yaml
@@ -3,6 +3,20 @@
 # Declare variables to be passed into your templates.
 
 data:
+  #Configmap
+  logLevel: "ERROR"
+  springProfilesActive: "gcp"
+  googleCloudProject: ""
+  googleAudiences: ""
+  entitlementsHost: "http://entitlements"
+  partitionHost: "http://partition"
+  recordsChangedPubsubEndpoint: ""
+  storageHost: "http://storage"
+  serviceIdentity: "register-pubsub-identity"
+  keyRing: "csqp"
+  kmsKey: "registerService"
+  subscriberPrivateKeyId: "testkey"
+  # Deployment
   requestsCpu: "0.1"
   requestsMemory: "384M"
   limitsCpu: "1"
@@ -20,6 +34,7 @@ conf:
   appName: "register"
   onPremEnabled: false
   domain: ""
+  cicdEnabled: false
 
 istio:
   proxyCPU: "50m"
-- 
GitLab