mv pgpool to a subchart of postgres

Issue-ID: OOM-1355

Change-Id: I37a8906b2039eeaf46da5c3884a87b69a79db3ef
Signed-off-by: jasmineWen <jasmine.wen@amdocs.com>
diff --git a/kubernetes/common/pgpool/configs/pool_passwd b/kubernetes/common/pgpool/configs/pool_passwd
deleted file mode 100644
index d8e09a2..0000000
--- a/kubernetes/common/pgpool/configs/pool_passwd
+++ /dev/null
@@ -1 +0,0 @@
-testuser:md599e8713364988502fa6189781bcf648f
diff --git a/kubernetes/common/pgpool/templates/configmap.yaml b/kubernetes/common/pgpool/templates/configmap.yaml
deleted file mode 100755
index cc20b42..0000000
--- a/kubernetes/common/pgpool/templates/configmap.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-apiVersion: v1
-kind: ConfigMap
-metadata:
-  name: {{ .Release.Name }}-pgpool-configmap
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-data:
-{{ tpl (.Files.Glob "configs/*").AsConfig . | indent 2 }}
diff --git a/kubernetes/common/pgpool/templates/service.yaml b/kubernetes/common/pgpool/templates/service.yaml
deleted file mode 100644
index 0811fda..0000000
--- a/kubernetes/common/pgpool/templates/service.yaml
+++ /dev/null
@@ -1,14 +0,0 @@
-kind: "Service"
-apiVersion: "v1"
-metadata:
-  name: "pgpool"
-  labels:
-    name: "pgpool"
-spec: 
-  ports:
-    - protocol: "TCP"
-      port: 5432
-      targetPort: 5432
-  selector:
-    name: "pgpool"
-  type: ClusterIP
diff --git a/kubernetes/common/pgpool/values.yaml b/kubernetes/common/pgpool/values.yaml
deleted file mode 100644
index 8e74742..0000000
--- a/kubernetes/common/pgpool/values.yaml
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright © 2018 Amdocs, AT&T, Bell Canada
-#
-# 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.
-
-name: pgpool
-container:
-  port: 5432
-  name:
-    primary: pgset-primary
-    replica: pgset-replica
-credentials:
-  pgusername: testuser
-  pgpassword: password
-serviceType: ClusterIP
-image:
-  repository: crunchydata
-  container: crunchy-pgpool
-  tag: centos7-10.4-2.0.0
diff --git a/kubernetes/common/pgpool/Chart.yaml b/kubernetes/common/postgres/charts/pgpool/Chart.yaml
similarity index 100%
rename from kubernetes/common/pgpool/Chart.yaml
rename to kubernetes/common/postgres/charts/pgpool/Chart.yaml
diff --git a/kubernetes/common/pgpool/configs/pgpool.conf b/kubernetes/common/postgres/charts/pgpool/configs/pgpool.conf
similarity index 98%
rename from kubernetes/common/pgpool/configs/pgpool.conf
rename to kubernetes/common/postgres/charts/pgpool/configs/pgpool.conf
index 9dd979a..f335174 100644
--- a/kubernetes/common/pgpool/configs/pgpool.conf
+++ b/kubernetes/common/postgres/charts/pgpool/configs/pgpool.conf
@@ -52,12 +52,12 @@
 
 # - Backend Connection Settings -
 
-backend_hostname0 = '{{.Values.container.primary}}'
+backend_hostname0 = '{{.Values.container.name.primary}}'
 backend_port0 = 5432
 backend_weight0= 1
 backend_flag0= 'DISALLOW_TO_FAILOVER'
 
-backend_hostname1 = '{{.Values.container.replica}}'
+backend_hostname1 = '{{.Values.container.name.replica}}'
 backend_port1 = 5432
 backend_weight1= 1
 backend_flag1= 'DISALLOW_TO_FAILOVER'
@@ -259,7 +259,7 @@
 # LOAD BALANCING MODE
 #------------------------------------------------------------------------------
 
-load_balance_mode = off
+load_balance_mode = on
                                    # Activate load balancing mode
                                    # (change requires restart)
 ignore_leading_white_space = on
@@ -358,7 +358,7 @@
 health_check_timeout = 10
                                    # Health check timeout
                                    # 0 means no timeout
-health_check_user = '{{.Values.credentials.pguser}}'
+health_check_user = '{{.Values.credentials.pgusername}}'
                                    # Health check user
 health_check_password = '{{.Values.credentials.pgpassword}}'
                                    # Password for health check user
@@ -419,7 +419,7 @@
 # ONLINE RECOVERY
 #------------------------------------------------------------------------------
 
-recovery_user = '{{.Values.credentials.pguser}}'
+recovery_user = '{{.Values.credentials.pgusername}}'
                                    # Online recovery user
 recovery_password = '{{.Values.credentials.pgpassword}}'
                                    # Online recovery password
diff --git a/kubernetes/common/pgpool/configs/pool_hba.conf b/kubernetes/common/postgres/charts/pgpool/configs/pool_hba.conf
similarity index 100%
rename from kubernetes/common/pgpool/configs/pool_hba.conf
rename to kubernetes/common/postgres/charts/pgpool/configs/pool_hba.conf
diff --git a/kubernetes/common/postgres/charts/pgpool/configs/pool_passwd b/kubernetes/common/postgres/charts/pgpool/configs/pool_passwd
new file mode 100644
index 0000000..3636d1d
--- /dev/null
+++ b/kubernetes/common/postgres/charts/pgpool/configs/pool_passwd
@@ -0,0 +1,2 @@
+testuser:md599e8713364988502fa6189781bcf648f
+postgres:md53175bce1d3201d16594cebf9d7eb3f9d
diff --git a/kubernetes/common/pgpool/requirements.yaml b/kubernetes/common/postgres/charts/pgpool/requirements.yaml
similarity index 100%
rename from kubernetes/common/pgpool/requirements.yaml
rename to kubernetes/common/postgres/charts/pgpool/requirements.yaml
diff --git a/kubernetes/common/postgres/charts/pgpool/templates/configmap.yaml b/kubernetes/common/postgres/charts/pgpool/templates/configmap.yaml
new file mode 100755
index 0000000..10ebd7f
--- /dev/null
+++ b/kubernetes/common/postgres/charts/pgpool/templates/configmap.yaml
@@ -0,0 +1,26 @@
+# Copyright © 2017 Amdocs, Bell Canada
+#
+# 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.
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-pgpool-configmap
+  namespace: {{ include "common.namespace" . }}
+  labels:
+    app: {{ include "common.name" . }}
+    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+    release: {{ .Release.Name }}
+    heritage: {{ .Release.Service }}
+data:
+{{ tpl (.Files.Glob "configs/*").AsConfig . | indent 2 }}
diff --git a/kubernetes/common/pgpool/templates/deployment.yaml b/kubernetes/common/postgres/charts/pgpool/templates/deployment.yaml
similarity index 91%
rename from kubernetes/common/pgpool/templates/deployment.yaml
rename to kubernetes/common/postgres/charts/pgpool/templates/deployment.yaml
index f598409..a05bed4 100644
--- a/kubernetes/common/pgpool/templates/deployment.yaml
+++ b/kubernetes/common/postgres/charts/pgpool/templates/deployment.yaml
@@ -32,8 +32,9 @@
         release: {{ .Release.Name }}
     spec:
       containers:
-      - name: pgpool
-        image: "{{.Values.image.repository}}/{{.Values.image.container}}:{{.Values.image.tag}}"
+      - image: "{{.Values.repository}}/{{.Values.image}}"
+        imagePullPolicy: {{ .Values.pullPolicy | default .Values.global.pullPolicy }}
+        name: {{ include "common.name" . }}
         env:
         - name: PG_PRIMARY_SERVICE_NAME
           value: {{.Values.container.name.primary}}
diff --git a/kubernetes/common/postgres/charts/pgpool/templates/service.yaml b/kubernetes/common/postgres/charts/pgpool/templates/service.yaml
new file mode 100644
index 0000000..86442a2
--- /dev/null
+++ b/kubernetes/common/postgres/charts/pgpool/templates/service.yaml
@@ -0,0 +1,26 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.service.name }}
+  namespace: {{ include "common.namespace" . }}
+  labels:
+    app: {{ include "common.name" . }}
+    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+    release: {{ .Release.Name }}
+    heritage: {{ .Release.Service }}
+  annotations:
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    {{if eq .Values.service.type "NodePort" -}}
+    - port: {{ .Values.service.externalPort }}
+      nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }}
+      name: {{ .Values.service.name }}
+    {{- else -}}
+    - port: {{ .Values.service.externalPort }}
+      targetPort: {{ .Values.service.internalPort }}
+      name: {{ .Values.service.name }}
+    {{- end}}
+  selector:
+    app: {{ include "common.name" . }}
+    release: {{ .Release.Name }}
diff --git a/kubernetes/common/postgres/charts/pgpool/values.yaml b/kubernetes/common/postgres/charts/pgpool/values.yaml
new file mode 100644
index 0000000..cb732b7
--- /dev/null
+++ b/kubernetes/common/postgres/charts/pgpool/values.yaml
@@ -0,0 +1,44 @@
+# Copyright © 2018 Amdocs, AT&T, Bell Canada
+#
+# 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.
+
+#################################################################
+# Global configuration defaults.
+#################################################################
+global:
+  nodePortPrefix: 302
+  persistence: {}
+  readinessRepository: oomk8s
+  readinessImage: readiness-check:2.0.0
+
+#################################################################
+# Application configuration defaults.
+#################################################################
+# application image
+repository: crunchydata
+image: crunchy-pgpool:centos7-10.4-2.0.0
+pullPolicy: Always
+
+container:
+  port: 5432
+  name:
+    primary: pgset-primary
+    replica: pgset-replica
+credentials:
+  pgusername: testuser
+  pgpassword: password
+service:
+  name: pgpool 
+  type: ClusterIP
+  externalPort: 5432
+  internalPort: 5432