Merge "Support for dbaas(HA/SA) in deployment"
[ric-plt/ric-dep.git] / helm / dbaas / templates / statefulset.yaml
1 ################################################################################
2 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
3 #   Copyright (c) 2019 Nokia.                                                  #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 {{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaas.image.registry }}
18 ---
19 apiVersion: apps/v1
20 kind: StatefulSet
21 metadata:
22   name: {{ include "common.statefulsetname.dbaas" . }}-server
23   namespace: {{ include "common.namespace.platform" . }}
24   labels:
25     app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
26     chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
27     release: {{ .Release.Name }}
28     heritage: {{ .Release.Service }}
29 spec:
30   selector:
31     matchLabels:
32       app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
33       release: {{ .Release.Name }}
34   serviceName: {{ template "common.servicename.dbaas.tcp" . }}
35 {{- if $.Values.dbaas.enableHighAvailability }}
36   replicas: {{ .Values.dbaas.haReplicas }}
37 {{- else }}
38   replicas: {{ .Values.dbaas.saReplicas }}
39 {{- end }}
40   podManagementPolicy: OrderedReady
41   updateStrategy:
42     type: RollingUpdate
43   template:
44     metadata:
45       labels:
46         app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
47         release: {{ .Release.Name }}
48     spec:
49 {{- if $.Values.dbaas.enablePodAntiAffinity }}
50       affinity:
51         podAntiAffinity:
52           requiredDuringSchedulingIgnoredDuringExecution:
53             - labelSelector:
54                 matchLabels:
55                   app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
56                   release: {{ .Release.Name }}
57               topologyKey: kubernetes.io/hostname
58           preferredDuringSchedulingIgnoredDuringExecution:
59             - weight: 100
60               podAffinityTerm:
61                 labelSelector:
62                   matchLabels:
63                     app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaas" . }}
64                     release: {{ .Release.Name }}
65                 topologyKey: topology.kubernetes.io/zone
66 {{- end }}
67       imagePullSecrets:
68         {{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaas.image.registry }}
69         - name: {{ include "common.dockerregistry.credential" $ctx }}
70       terminationGracePeriodSeconds: {{ .Values.dbaas.terminationGracePeriodSeconds }}
71 {{- if $.Values.dbaas.enableHighAvailability }}
72       initContainers:
73       - name: config-init
74         image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
75         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
76         command:
77         - sh
78         args:
79         - /readonly-config/init.sh
80         env:
81         - name: ANNOUNCE_IP
82           valueFrom:
83             fieldRef:
84               fieldPath: status.podIP
85         volumeMounts:
86         - name: config
87           mountPath: /readonly-config
88           readOnly: true
89         - name: data
90           mountPath: /data
91 {{- end }}
92       containers:
93       - name: {{ include "common.containername.dbaas" . }}-redis
94         image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
95         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
96         command:
97         - redis-server
98         args:
99 {{- if $.Values.dbaas.enableHighAvailability }}
100         - /data/conf/redis.conf
101 {{- else }}
102         - /data/redis.conf
103 {{- end }}
104         livenessProbe:
105           exec:
106             command: 
107             - /bin/sh
108             - -c
109             - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
110           initialDelaySeconds: 15
111           periodSeconds: 5
112         readinessProbe:
113           exec:
114             command: 
115             - /bin/sh
116             - -c
117             - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
118           initialDelaySeconds: 15
119           periodSeconds: 5
120         ports:
121         - name: redis
122           containerPort: {{ include "common.serviceport.dbaas.redis" . }}
123         volumeMounts:
124         - mountPath: /data
125 {{- if $.Values.dbaas.enableHighAvailability }}
126           name: data
127       - name: {{ include "common.containername.dbaas" . }}-sentinel
128         image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
129         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
130         command:
131           - redis-server
132         args:
133           - /data/conf/sentinel.conf
134           - --sentinel
135         livenessProbe:
136           exec:
137             command: 
138             - /bin/sh
139             - -c
140             - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
141           initialDelaySeconds: 15
142           periodSeconds: 5
143         readinessProbe:
144           exec:
145             command: 
146             - /bin/sh
147             - -c
148             - timeout -t {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
149           initialDelaySeconds: 15
150           periodSeconds: 5
151         ports:
152           - name: sentinel
153             containerPort: {{ include "common.serviceport.dbaas.sentinel" . }}
154         volumeMounts:
155         - mountPath: /data
156           name: data
157 {{- else }}
158           name: config
159 {{- end }}
160       volumes:
161       - name: config
162         configMap:
163           name: {{ template "common.configmapname.dbaas" . }}-config
164 {{- if $.Values.dbaas.enableHighAvailability }}
165       - name: data
166         emptyDir: {}
167 {{- end }}