From ab105c9061d94d784008fd3dcc6e895d3620548e Mon Sep 17 00:00:00 2001
From: "Siarhei Symanovich (EPAM)" <siarhei_symanovich@epam.com>
Date: Fri, 3 Feb 2023 16:09:28 +0000
Subject: [PATCH] Added redis service for notification in GC

---
 devops/gc/deploy/README.md                    |  5 ++-
 devops/gc/deploy/templates/configmap.yaml     |  6 ++++
 devops/gc/deploy/templates/deploy-redis.yaml  | 35 +++++++++++++++++++
 devops/gc/deploy/templates/deployment.yaml    |  2 ++
 devops/gc/deploy/templates/service-redis.yaml | 14 ++++++++
 devops/gc/deploy/values.yaml                  |  7 ++++
 6 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 devops/gc/deploy/templates/deploy-redis.yaml
 create mode 100644 devops/gc/deploy/templates/service-redis.yaml

diff --git a/devops/gc/deploy/README.md b/devops/gc/deploy/README.md
index 3a58224f7..db8a9e5c3 100644
--- a/devops/gc/deploy/README.md
+++ b/devops/gc/deploy/README.md
@@ -36,7 +36,8 @@ First you need to set variables in **values.yaml** file using any code editor. S
 **entitlementsHost** | entitlements service host address | string | `http://entitlements` | yes
 **registerHost** | register service host address | string | `http://register` | yes
 **partitionHost** | partition service host address | string | `http://partition` | yes
-
+**redisNotificationHost** | The host for redis instance. If empty, helm installs an internal redis instance | string | `redis-ent-master` | yes
+**redisNotificationPort** | The port for redis instance | digit | 6379 | yes
 ### Deployment variables
 
 | Name | Description | Type | Default |Required |
@@ -48,6 +49,7 @@ First you need to set variables in **values.yaml** file using any code editor. S
 **serviceAccountName** | name of your service account | string | `notification` | yes
 **imagePullPolicy** | when to pull image | string | `IfNotPresent` | yes
 **image** | service image | string | - | yes
+**redisImage** | redis image | string | `redis:7` | yes
 
 ### Config variables
 
@@ -57,6 +59,7 @@ First you need to set variables in **values.yaml** file using any code editor. S
 **configmap** | configmap to be used | string | `notification-config` | yes
 **rabbitmqSecretName** | secret for rabbitmq | string | `rabbitmq-secret` | yes
 **openidSecretName** | secret for openid | string | `notification-keycloak-secret` | yes
+**notificationRedisSecretName** | Notification redis secret | string | `notification-redis-secret` | yes
 **onPremEnabled** | whether on-prem is enabled | boolean | false | yes
 **domain** | your domain, ex `example.com` | string | - | yes
 
diff --git a/devops/gc/deploy/templates/configmap.yaml b/devops/gc/deploy/templates/configmap.yaml
index 3099712be..4028d5ede 100644
--- a/devops/gc/deploy/templates/configmap.yaml
+++ b/devops/gc/deploy/templates/configmap.yaml
@@ -11,5 +11,11 @@ data:
   ENTITLEMENTS_HOST: {{ .Values.data.entitlementsHost  | quote}}
   REGISTER_HOST: {{ .Values.data.registerHost  | quote}}
   PARTITION_HOST: {{ .Values.data.partitionHost  | quote}}
+  REDIS_PORT: {{ .Values.data.redisNotificationPort | quote }}
+  {{- if .Values.data.redisNotificationHost }}
+  REDIS_HOST: {{ .Values.data.redisNotificationHost | quote }}
+  {{- else }}
+  REDIS_HOST: {{ printf "redis-%s" .Values.conf.appName | quote }}
+  {{- end }}
   {{- if not .Values.conf.onPremEnabled }}
   {{- end }}
diff --git a/devops/gc/deploy/templates/deploy-redis.yaml b/devops/gc/deploy/templates/deploy-redis.yaml
new file mode 100644
index 000000000..47d2d2ca8
--- /dev/null
+++ b/devops/gc/deploy/templates/deploy-redis.yaml
@@ -0,0 +1,35 @@
+{{ if not .Values.data.redisNotificationHost }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ printf "redis-%s" .Values.conf.appName | quote }}
+  namespace: {{ .Release.Namespace | quote }}
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: {{ printf "redis-%s" .Values.conf.appName | quote }}
+  template:
+    metadata:
+      labels:
+        app: {{ printf "redis-%s" .Values.conf.appName | quote }}
+      annotations:
+        sidecar.istio.io/proxyCPU: 30m
+    spec:
+      containers:
+      - args:
+        - --requirepass
+        - $(REDIS_PASSWORD)
+        envFrom:
+        - secretRef:
+            name: {{ .Values.conf.notificationRedisSecretName | quote }}
+        image: {{ .Values.data.redisImage | quote }}
+        imagePullPolicy: {{ .Values.data.imagePullPolicy | quote }}
+        name: {{ printf "redis-%s" .Values.conf.appName | quote }}
+        ports:
+        - containerPort: 6379
+          protocol: TCP
+        resources:
+          requests:
+            memory: 100Mi
+{{ end }}
diff --git a/devops/gc/deploy/templates/deployment.yaml b/devops/gc/deploy/templates/deployment.yaml
index 4fcb41573..40c4a8eb5 100644
--- a/devops/gc/deploy/templates/deployment.yaml
+++ b/devops/gc/deploy/templates/deployment.yaml
@@ -28,6 +28,8 @@ spec:
           envFrom:
           - configMapRef:
               name: {{ .Values.conf.configmap  | quote}}
+          - secretRef:
+              name: {{ .Values.conf.notificationRedisSecretName | quote }}
           {{- if .Values.conf.onPremEnabled }}
           - secretRef:
               name: {{ .Values.conf.rabbitmqSecretName  | quote}}
diff --git a/devops/gc/deploy/templates/service-redis.yaml b/devops/gc/deploy/templates/service-redis.yaml
new file mode 100644
index 000000000..0bc4b8fd3
--- /dev/null
+++ b/devops/gc/deploy/templates/service-redis.yaml
@@ -0,0 +1,14 @@
+{{ if not .Values.data.redisNotificationHost }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ printf "redis-%s" .Values.conf.appName | quote }}
+  namespace: {{ .Release.Namespace | quote }}
+spec:
+  ports:
+  - port: {{ .Values.data.redisNotificationPort }}
+    protocol: TCP
+    targetPort: 6379
+  selector:
+    app: {{ printf "redis-%s" .Values.conf.appName | quote }}
+{{ end }}
diff --git a/devops/gc/deploy/values.yaml b/devops/gc/deploy/values.yaml
index c166b37a1..dd6930090 100644
--- a/devops/gc/deploy/values.yaml
+++ b/devops/gc/deploy/values.yaml
@@ -5,6 +5,10 @@ data:
   entitlementsHost: "http://entitlements"
   registerHost: "http://register"
   partitionHost: "http://partition"
+  # redis connection. Change it if you want to use external redis
+  redisNotificationHost: ""
+  redisNotificationPort: 6379
+  redisImage: "docker.io/library/redis:7"
   #Deployments
   requestsCpu: "0.1"
   requestsMemory: "256M"
@@ -19,8 +23,11 @@ conf:
   appName: "notification"
   rabbitmqSecretName: "rabbitmq-secret"
   openidSecretName: "notification-keycloak-secret"
+  notificationRedisSecretName: "notification-redis-secret"
   onPremEnabled: false
   domain: ""
+#FIXME fix condition with redis ssl configuration
+#  redisSSL: false
 
 istio:
   proxyCPU: "50m"
-- 
GitLab