DBaaS standalone and HA version update
[ric-plt/ric-dep.git] / helm / dbaas / templates / statefulset.yaml
similarity index 55%
rename from helm/dbaasha/templates/statefulset.yaml
rename to helm/dbaas/templates/statefulset.yaml
index 9b068da..217f22b 100644 (file)
 #   See the License for the specific language governing permissions and        #
 #   limitations under the License.                                             #
 ################################################################################
-{{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaasha.image.registry }}
+{{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaas.image.registry }}
 ---
 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
-  name: {{ include "common.statefulsetname.dbaasha" . }}-server
+  name: {{ include "common.statefulsetname.dbaas" . }}-server
   namespace: {{ include "common.namespace.platform" . }}
   labels:
-    app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+    app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
     release: {{ .Release.Name }}
     heritage: {{ .Release.Service }}
 spec:
   selector:
     matchLabels:
-      app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+      app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
       release: {{ .Release.Name }}
-  serviceName: {{ template "common.servicename.dbaasha.tcp" . }}
-  replicas: {{ .Values.dbaasha.replicas }}
+  serviceName: {{ template "common.servicename.dbaas.tcp" . }}
+{{- if $.Values.dbaas.enableHighAvailability }}
+  replicas: {{ .Values.dbaas.haReplicas }}
+{{- else }}
+  replicas: {{ .Values.dbaas.saReplicas }}
+{{- end }}
   podManagementPolicy: OrderedReady
   updateStrategy:
     type: RollingUpdate
   template:
     metadata:
       labels:
-        app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+        app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
         release: {{ .Release.Name }}
     spec:
-      {{- if .Values.dbaasha.nodeSelector }}
-      nodeSelector:
-{{ toYaml .Values.dbaasha.nodeSelector | indent 8 }}
-      {{- end }}
-    {{- with .Values.dbaasha.affinity }}
+{{- if $.Values.dbaas.enablePodAntiAffinity }}
       affinity:
-{{ tpl . $ | indent 8 }}
-    {{- end }}
+        podAntiAffinity:
+          requiredDuringSchedulingIgnoredDuringExecution:
+            - labelSelector:
+                matchLabels:
+                  app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
+                  release: {{ .Release.Name }}
+              topologyKey: kubernetes.io/hostname
+          preferredDuringSchedulingIgnoredDuringExecution:
+            - weight: 100
+              podAffinityTerm:
+                labelSelector:
+                  matchLabels:
+                    app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
+                    release: {{ .Release.Name }}
+                topologyKey: topology.kubernetes.io/zone
+{{- end }}
       imagePullSecrets:
-        {{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaasha.image.registry }}
+        {{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaas.image.registry }}
         - name: {{ include "common.dockerregistry.credential" $ctx }}
+      terminationGracePeriodSeconds: {{ .Values.dbaas.terminationGracePeriodSeconds }}
+{{- if $.Values.dbaas.enableHighAvailability }}
       initContainers:
-      {{- if .Values.dbaasha.sysctlImage.enabled }}
-      - name: init-systctl
-        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaasha.image.name }}:{{ .Values.dbaasha.image.tag }}
-        imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
-        {{ if .Values.dbaasha.sysctlImage.mountHostSys }}
-        volumeMounts:
-          - name: host-sys
-            mountPath: /host-sys
-        {{- end }}
-        command:
-{{ toYaml .Values.dbaasha.sysctlImage.command | indent 10 }}
-        securityContext:
-          runAsNonRoot: false
-          privileged: true
-          runAsUser: 0
-      {{- end }}
       - name: config-init
-        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaasha.image.name }}:{{ .Values.dbaasha.image.tag }}
+        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
         command:
         - sh
         args:
         - /readonly-config/init.sh
+        env:
+        - name: ANNOUNCE_IP
+          valueFrom:
+            fieldRef:
+              fieldPath: status.podIP
         volumeMounts:
         - name: config
           mountPath: /readonly-config
           readOnly: true
         - name: data
           mountPath: /data
+{{- end }}
       containers:
-      - name: {{ include "common.containername.dbaasha.redis" . }}
-        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaasha.image.name }}:{{ .Values.dbaasha.image.tag }}
+      - name: {{ include "common.containername.dbaas" . }}-redis
+        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
         command:
         - redis-server
         args:
+{{- if $.Values.dbaas.enableHighAvailability }}
         - /data/conf/redis.conf
+{{- else }}
+        - /data/redis.conf
+{{- end }}
         livenessProbe:
           exec:
-            command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+            command: 
+            - /bin/sh
+            - -c
+            - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
           initialDelaySeconds: 15
           periodSeconds: 5
         readinessProbe:
           exec:
-            command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+            command: 
+            - /bin/sh
+            - -c
+            - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
           initialDelaySeconds: 15
           periodSeconds: 5
         ports:
         - name: redis
-          containerPort: {{ include "common.serviceport.dbaasha.redis" . }}
+          containerPort: {{ include "common.serviceport.dbaas.redis" . }}
         volumeMounts:
         - mountPath: /data
+{{- if $.Values.dbaas.enableHighAvailability }}
           name: data
-        - mountPath: /probes
-          name: probes
-      - name: {{ include "common.containername.dbaasha.sentinel" . }}
-        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaasha.image.name }}:{{ .Values.dbaasha.image.tag }}
+      - name: {{ include "common.containername.dbaas" . }}-sentinel
+        image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
         command:
           - redis-server
@@ -119,33 +134,34 @@ spec:
           - --sentinel
         livenessProbe:
           exec:
-            command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+            command: 
+            - /bin/sh
+            - -c
+            - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
           initialDelaySeconds: 15
           periodSeconds: 5
         readinessProbe:
           exec:
-            command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+            command: 
+            - /bin/sh
+            - -c
+            - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
           initialDelaySeconds: 15
           periodSeconds: 5
         ports:
           - name: sentinel
-            containerPort: {{ include "common.serviceport.dbaasha.sentinel" . }}
+            containerPort: {{ include "common.serviceport.dbaas.sentinel" . }}
         volumeMounts:
         - mountPath: /data
           name: data
-        - mountPath: /probes
-          name: probes
+{{- else }}
+          name: config
+{{- end }}
       volumes:
       - name: config
         configMap:
-          name: {{ template "common.configmapname.dbaasha" . }}-config
-      - name: probes
-        configMap:
-          name: {{ template "common.configmapname.dbaasha" . }}-probes
-      {{- if .Values.dbaasha.sysctlImage.mountHostSys }}
-      - name: host-sys
-        hostPath:
-          path: /sys
-      {{- end }}
+          name: {{ template "common.configmapname.dbaas" . }}-config
+{{- if $.Values.dbaas.enableHighAvailability }}
       - name: data
         emptyDir: {}
+{{- end }}