From c0b522d3c7ece1e7631a7193e768f97cb336293d Mon Sep 17 00:00:00 2001
From: "Krisztian Molnar (EPAM)" <krisztian_molnar@epam.com>
Date: Wed, 13 Jul 2022 12:50:57 +0000
Subject: [PATCH] GONRG-5020: Refactor variables to camelCase

---
 .editorconfig                                 |  4 +
 devops/gcp/configmap/README.md                | 74 +++++++++++++++++++
 devops/gcp/configmap/templates/variables.yaml | 26 +++----
 devops/gcp/configmap/values.yaml              | 26 +++----
 devops/gcp/deploy/README.md                   | 70 ++++++++++++++++++
 devops/gcp/deploy/templates/deployment.yaml   | 26 +++----
 .../gcp/deploy/templates/service-account.yaml |  2 +-
 devops/gcp/deploy/templates/service.yaml      |  6 +-
 .../gcp/deploy/templates/virtual-service.yaml |  8 +-
 devops/gcp/deploy/values.yaml                 | 18 ++---
 provider/indexer-gcp/docker/Dockerfile        |  6 --
 .../indexer-gcp/docker/docker-compose.yml     | 12 ---
 .../resources/application-anthos.properties   |  2 +-
 .../main/resources/application-gcp.properties |  2 +-
 14 files changed, 207 insertions(+), 75 deletions(-)
 create mode 100644 .editorconfig
 create mode 100644 devops/gcp/configmap/README.md
 create mode 100644 devops/gcp/deploy/README.md
 delete mode 100644 provider/indexer-gcp/docker/Dockerfile
 delete mode 100644 provider/indexer-gcp/docker/docker-compose.yml

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000000000..5b462cccd
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,4 @@
+root = true
+
+[*]
+insert_final_newline = true
diff --git a/devops/gcp/configmap/README.md b/devops/gcp/configmap/README.md
new file mode 100644
index 000000000..6ecc6fe4f
--- /dev/null
+++ b/devops/gcp/configmap/README.md
@@ -0,0 +1,74 @@
+<!--- 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 |
+|------|-------------|------|---------|---------|
+**entitlementsHost** | entitlements host | string | "http://entitlements" | yes
+**indexerQueueHost** | indexer-queue host | string | "http://indexer-queue" | yes
+**logLevel** | logging level | string | INFO | yes
+**partitionHost** | partition host | string | "http://partition" | yes
+**redisGroupHost** | redis group host | string | redis-group-master | yes
+**redisSearchHost** | redis search host | string | redis-search-master | yes
+**schemaHost** | schema host | string | "http://schema" | yes
+**securityHttpsCertificateTrust** | whether https is enabled | boolean | true | yes
+**springProfilesActive** | active spring profile | string | gcp | yes
+**storageHost** | storage host | string | "http://storage" | yes
+
+### GCP variables
+
+| Name | Description | Type | Default |Required |
+|------|-------------|------|---------|---------|
+**googleAudiences** | your GCP client ID | string | - | yes
+
+### Config variables
+
+| Name | Description | Type | Default |Required |
+|------|-------------|------|---------|---------|
+**configmap** | configmap to be used | string | indexer-config | yes
+**appName** | name of the app | string | indexer | 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-indexer-configmap .
+```
+
+## Uninstalling the Chart
+
+To uninstall the helm deployment:
+
+```console
+helm uninstall gcp-indexer-configmap
+```
+
+[Move-to-Top](#configmap-helm-chart)
diff --git a/devops/gcp/configmap/templates/variables.yaml b/devops/gcp/configmap/templates/variables.yaml
index a429f4f98..0988de143 100644
--- a/devops/gcp/configmap/templates/variables.yaml
+++ b/devops/gcp/configmap/templates/variables.yaml
@@ -2,20 +2,20 @@ apiVersion: v1
 kind: ConfigMap
 metadata:
   labels:
-    app: "{{ .Values.conf.app_name }}"
+    app: "{{ .Values.conf.appName }}"
   name: "{{ .Values.conf.configmap }}"
   namespace: "{{ .Release.Namespace }}"
 data:
-  ENTITLEMENTS_HOST: "{{ .Values.data.entitlements_host }}"
-  INDEXER_QUEUE_BASE_HOST: "{{ .Values.data.indexer_queue_base_host }}"
-  LOG_LEVEL: "{{ .Values.data.log_level }}"
-  PARTITION_HOST: "{{ .Values.data.partition_host }}"
-  REDIS_GROUP_HOST: "{{ .Values.data.redis_group_host }}"
-  REDIS_SEARCH_HOST: "{{ .Values.data.redis_search_host }}"
-  SCHEMA_BASE_HOST: "{{ .Values.data.schema_base_host }}"
-  SECURITY_HTTPS_CERTIFICATE_TRUST: "{{ .Values.data.security_https_certificate_trust }}"
-  SPRING_PROFILES_ACTIVE: "{{ .Values.data.spring_profiles_active }}"
-  STORAGE_HOST: "{{ .Values.data.storage_host }}"
-  {{- if not .Values.conf.on_prem_enabled }}
-  GOOGLE_AUDIENCES: "{{ .Values.data.google_audiences }}"
+  ENTITLEMENTS_HOST: "{{ .Values.data.entitlementsHost }}"
+  INDEXER_QUEUE_BASE_HOST: "{{ .Values.data.indexerQueueHost }}"
+  LOG_LEVEL: "{{ .Values.data.logLevel }}"
+  PARTITION_HOST: "{{ .Values.data.partitionHost }}"
+  REDIS_GROUP_HOST: "{{ .Values.data.redisGroupHost }}"
+  REDIS_SEARCH_HOST: "{{ .Values.data.redisSearchHost }}"
+  SCHEMA_BASE_HOST: "{{ .Values.data.schemaHost }}"
+  SECURITY_HTTPS_CERTIFICATE_TRUST: "{{ .Values.data.securityHttpsCertificateTrust }}"
+  SPRING_PROFILES_ACTIVE: "{{ .Values.data.springProfilesActive }}"
+  STORAGE_HOST: "{{ .Values.data.storageHost }}"
+  {{- if not .Values.conf.onPremEnabled }}
+  GOOGLE_AUDIENCES: "{{ .Values.data.googleAudiences }}"
   {{- end }}
diff --git a/devops/gcp/configmap/values.yaml b/devops/gcp/configmap/values.yaml
index 340c11278..84a3f7939 100644
--- a/devops/gcp/configmap/values.yaml
+++ b/devops/gcp/configmap/values.yaml
@@ -4,19 +4,19 @@
 
 data:
   # common
-  entitlements_host: "http://entitlements"
-  indexer_queue_base_host: "http://indexer-queue"
-  log_level: "INFO"
-  partition_host: "http://partition"
-  redis_group_host: "redis-group-master"
-  redis_search_host: "redis-search-master"
-  schema_base_host: "http://schema"
-  security_https_certificate_trust: "true"
-  spring_profiles_active: "gcp"
-  storage_host: "http://storage"
+  entitlementsHost: "http://entitlements"
+  indexerQueueHost: "http://indexer-queue"
+  logLevel: "INFO"
+  partitionHost: "http://partition"
+  redisGroupHost: "redis-group-master"
+  redisSearchHost: "redis-search-master"
+  schemaHost: "http://schema"
+  securityHttpsCertificateTrust: "true"
+  springProfilesActive: "gcp"
+  storageHost: "http://storage"
   # gcp
-  google_audiences: ""
+  googleAudiences: ""
 conf:
-  app_name: "indexer"
+  appName: "indexer"
   configmap: "indexer-config"
-  on_prem_enabled: false
+  onPremEnabled: false
diff --git a/devops/gcp/deploy/README.md b/devops/gcp/deploy/README.md
new file mode 100644
index 000000000..91af57954
--- /dev/null
+++ b/devops/gcp/deploy/README.md
@@ -0,0 +1,70 @@
+<!--- Deploy -->
+
+# Deploy helm chart
+
+## Introduction
+
+This chart bootstraps a 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
+
+Before installing deploy Helm chart you need to install [configmap Helm chart](../configmap).
+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 |
+|------|-------------|------|---------|---------|
+**requestsCpu** | amount of requested CPU | string | 0.1 | yes
+**requestsMemory** | amount of requested memory| string | 640M | yes
+**limitsCpu** | CPU limit | string | 1 | yes
+**limitsMemory** | memory limit | string | 1G | yes
+**image** | service image | string | - | yes
+**imagePullPolicy** | when to pull image | string | IfNotPresent | yes
+**serviceAccountName** | name of your service account | string | indexer | yes
+
+### Config variables
+
+| Name | Description | Type | Default |Required |
+|------|-------------|------|---------|---------|
+**appName** | name of the app | string | `indexer` | yes
+**configmap** | configmap to be used | string | `indexer-config` | yes
+**elasticSecretName** | secret for elastic | string | `indexer-elastic-secret` | yes
+**keycloakSecretName** | secret for keycloak | string | `indexer-keycloak-secret` | yes
+**rabbitmqSecretName** | secret for rabbitmq | string | `rabbitmq-secret` | yes
+**onPremEnabled** | whether on-prem is enabled | boolean | false | yes
+**domain** | your domain | string | - | yes
+
+### Install the helm chart
+
+Run this command from within this directory:
+
+```console
+helm install gcp-indexer-deploy .
+```
+
+## Uninstalling the Chart
+
+To uninstall the helm deployment:
+
+```console
+helm uninstall gcp-indexer-deploy
+```
+
+[Move-to-Top](#deploy-helm-chart)
diff --git a/devops/gcp/deploy/templates/deployment.yaml b/devops/gcp/deploy/templates/deployment.yaml
index 149c9f097..8c883af78 100644
--- a/devops/gcp/deploy/templates/deployment.yaml
+++ b/devops/gcp/deploy/templates/deployment.yaml
@@ -2,35 +2,35 @@ apiVersion: apps/v1
 kind: Deployment
 metadata:
   labels:
-    app: "{{ .Values.conf.app_name }}"
-  name: "{{ .Values.conf.app_name }}"
+    app: "{{ .Values.conf.appName }}"
+  name: "{{ .Values.conf.appName }}"
   namespace: "{{ .Release.Namespace }}"
 spec:
   selector:
     matchLabels:
-      app: "{{ .Values.conf.app_name }}"
+      app: "{{ .Values.conf.appName }}"
   replicas: 1
   template:
     metadata:
       labels:
-        app: "{{ .Values.conf.app_name }}"
+        app: "{{ .Values.conf.appName }}"
       annotations:
         rollme: {{ randAlphaNum 5 | quote }}
     spec:
       containers:
-      - name: "{{ .Values.conf.app_name }}"
+      - name: "{{ .Values.conf.appName }}"
         image: "{{ .Values.data.image }}"
         imagePullPolicy: "{{ .Values.data.imagePullPolicy }}"
         envFrom:
         - configMapRef:
             name: "{{ .Values.conf.configmap }}"
         - secretRef:
-            name: "{{ .Values.conf.elastic_secret_name }}"
-        {{- if .Values.conf.on_prem_enabled }}
+            name: "{{ .Values.conf.elasticSecretName }}"
+        {{- if .Values.conf.onPremEnabled }}
         - secretRef:
-            name: "{{ .Values.conf.keycloak_secret_name }}"
+            name: "{{ .Values.conf.keycloakSecretName }}"
         - secretRef:
-            name: "{{ .Values.conf.rabbitmq_secret_name }}"
+            name: "{{ .Values.conf.rabbitmqSecretName }}"
         {{- end }}
         securityContext:
           allowPrivilegeEscalation: false
@@ -39,9 +39,9 @@ spec:
         - containerPort: 8080
         resources:
           requests:
-            cpu: "{{ .Values.data.requests_cpu }}"
-            memory: "{{ .Values.data.requests_memory }}"
+            cpu: "{{ .Values.data.requestsCpu }}"
+            memory: "{{ .Values.data.requestsMemory }}"
           limits:
-            cpu: "{{ .Values.data.limits_cpu }}"
-            memory: "{{ .Values.data.limits_memory }}"
+            cpu: "{{ .Values.data.limitsCpu }}"
+            memory: "{{ .Values.data.limitsMemory }}"
       serviceAccountName: "{{ .Values.data.serviceAccountName }}"
diff --git a/devops/gcp/deploy/templates/service-account.yaml b/devops/gcp/deploy/templates/service-account.yaml
index 3fede170c..25fd74efb 100644
--- a/devops/gcp/deploy/templates/service-account.yaml
+++ b/devops/gcp/deploy/templates/service-account.yaml
@@ -1,4 +1,4 @@
-{{- if .Values.conf.on_prem_enabled }}
+{{- if .Values.conf.onPremEnabled }}
 apiVersion: v1
 kind: ServiceAccount
 metadata:
diff --git a/devops/gcp/deploy/templates/service.yaml b/devops/gcp/deploy/templates/service.yaml
index 86a626642..b7e02b2ed 100644
--- a/devops/gcp/deploy/templates/service.yaml
+++ b/devops/gcp/deploy/templates/service.yaml
@@ -1,11 +1,11 @@
 apiVersion: v1
 kind: Service
 metadata:
-  {{- if not .Values.conf.on_prem_enabled }}
+  {{- if not .Values.conf.onPremEnabled }}
   annotations:
     cloud.google.com/neg: '{"ingress": true}'
   {{- end }}
-  name: "{{ .Values.conf.app_name }}"
+  name: "{{ .Values.conf.appName }}"
   namespace: "{{ .Release.Namespace }}"
 spec:
   ports:
@@ -14,4 +14,4 @@ spec:
       targetPort: 8080
       name: http
   selector:
-    app: "{{ .Values.conf.app_name }}"
+    app: "{{ .Values.conf.appName }}"
diff --git a/devops/gcp/deploy/templates/virtual-service.yaml b/devops/gcp/deploy/templates/virtual-service.yaml
index 321945b4a..30ebb98ae 100644
--- a/devops/gcp/deploy/templates/virtual-service.yaml
+++ b/devops/gcp/deploy/templates/virtual-service.yaml
@@ -1,12 +1,14 @@
 apiVersion: networking.istio.io/v1alpha3
 kind: VirtualService
 metadata:
-  name: "{{ .Values.conf.app_name }}"
+  name: "{{ .Values.conf.appName }}"
   namespace: "{{ .Release.Namespace }}"
 spec:
   hosts:
-    {{- if .Values.conf.domain }}
+    {{- if and .Values.conf.domain .Values.conf.onPremEnabled }}
     - {{ printf "osdu.%s" .Values.conf.domain | quote }}
+    {{- else if .Values.conf.domain }}
+    - {{ .Values.conf.domain | quote }}
     {{- else }}
     - "*"
     {{- end }}
@@ -20,4 +22,4 @@ spec:
         - destination:
             port:
               number: 80
-            host: "{{ .Values.conf.app_name }}.{{ .Release.Namespace }}.svc.cluster.local"
+            host: "{{ .Values.conf.appName }}.{{ .Release.Namespace }}.svc.cluster.local"
diff --git a/devops/gcp/deploy/values.yaml b/devops/gcp/deploy/values.yaml
index fd467615a..2ef4cb886 100644
--- a/devops/gcp/deploy/values.yaml
+++ b/devops/gcp/deploy/values.yaml
@@ -3,18 +3,18 @@
 # Declare variables to be passed into your templates.
 
 data:
-  requests_cpu: "0.1"
-  requests_memory: "640M"
-  limits_cpu: "1"
-  limits_memory: "1G"
+  requestsCpu: "0.1"
+  requestsMemory: "640M"
+  limitsCpu: "1"
+  limitsMemory: "1G"
   image: ""
   imagePullPolicy: "IfNotPresent"
   serviceAccountName: "indexer"
 conf:
-  app_name: "indexer"
+  appName: "indexer"
   configmap: "indexer-config"
-  elastic_secret_name: "indexer-elastic-secret"
-  keycloak_secret_name: "indexer-keycloak-secret"
-  on_prem_enabled: false
-  rabbitmq_secret_name: "rabbitmq-secret"
+  elasticSecretName: "indexer-elastic-secret"
+  keycloakSecretName: "indexer-keycloak-secret"
+  rabbitmqSecretName: "rabbitmq-secret"
+  onPremEnabled: false
   domain: ""
diff --git a/provider/indexer-gcp/docker/Dockerfile b/provider/indexer-gcp/docker/Dockerfile
deleted file mode 100644
index 926302723..000000000
--- a/provider/indexer-gcp/docker/Dockerfile
+++ /dev/null
@@ -1,6 +0,0 @@
-FROM openjdk:8-slim
-VOLUME /tmp
-ARG JAR_FILE
-COPY ${JAR_FILE} app.jar
-ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","-Dspring.profiles.active=kuber","/app.jar"]
-EXPOSE 8080
diff --git a/provider/indexer-gcp/docker/docker-compose.yml b/provider/indexer-gcp/docker/docker-compose.yml
deleted file mode 100644
index 4d9b01efd..000000000
--- a/provider/indexer-gcp/docker/docker-compose.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-version: "3"
-services:
-  os-indexer-app:
-    build:
-      args: 
-        JAR_FILE: target/indexer-gcp-1.0.4-SNAPSHOT-spring-boot.jar
-      context: ..
-      dockerfile: docker/Dockerfile
-    image: gcr.io/opendes/os-indexer-app
-    ports:
-     - "8080:8080"
-
diff --git a/provider/indexer-gcp/src/main/resources/application-anthos.properties b/provider/indexer-gcp/src/main/resources/application-anthos.properties
index 9e5536614..67e63d39f 100644
--- a/provider/indexer-gcp/src/main/resources/application-anthos.properties
+++ b/provider/indexer-gcp/src/main/resources/application-anthos.properties
@@ -3,4 +3,4 @@ service.token.provider=OPENID
 partition-auth-enabled=false
 openid.provider-url=
 openid.provider-client-id=
-openid.provider-client-secret=
\ No newline at end of file
+openid.provider-client-secret=
diff --git a/provider/indexer-gcp/src/main/resources/application-gcp.properties b/provider/indexer-gcp/src/main/resources/application-gcp.properties
index fd738d7f4..8ac15c3f9 100644
--- a/provider/indexer-gcp/src/main/resources/application-gcp.properties
+++ b/provider/indexer-gcp/src/main/resources/application-gcp.properties
@@ -1,3 +1,3 @@
 oqmDriver=pubsub
 service.token.provider=GCP
-partition-auth-enabled=true
\ No newline at end of file
+partition-auth-enabled=true
-- 
GitLab