Adding Configmap for RIC service.
[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       shareProcessNamespace: true
93       containers:
94       - name: {{ include "common.containername.dbaas" . }}-redis
95         image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
96         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
97         command:
98         - redis-server
99         args:
100 {{- if $.Values.dbaas.enableHighAvailability }}
101         - /data/conf/redis.conf
102 {{- else }}
103         - /data/redis.conf
104 {{- end }}
105         livenessProbe:
106           exec:
107             command: 
108             - /bin/sh
109             - -c
110             - {{ .Values.dbaas.probeTimeoutCommand }} {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
111           initialDelaySeconds: 15
112           periodSeconds: 5
113         readinessProbe:
114           exec:
115             command: 
116             - /bin/sh
117             - -c
118             - {{ .Values.dbaas.probeTimeoutCommand }} {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
119           initialDelaySeconds: 15
120           periodSeconds: 5
121         ports:
122         - name: redis
123           containerPort: {{ include "common.serviceport.dbaas.redis" . }}
124         envFrom:
125         - configMapRef:
126             name: {{ include "common.configmapname.dbaas" . }}-appconfig
127         volumeMounts:
128         - mountPath: /data
129 {{- if $.Values.dbaas.enableHighAvailability }}
130           name: data
131       - name: {{ include "common.containername.dbaas" . }}-sentinel
132         image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaas.image.name }}:{{ .Values.dbaas.image.tag }}
133         imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx  }}
134         command:
135           - redis-server
136         args:
137           - /data/conf/sentinel.conf
138           - --sentinel
139         livenessProbe:
140           exec:
141             command: 
142             - /bin/sh
143             - -c
144             - {{ .Values.dbaas.probeTimeoutCommand }} {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
145           initialDelaySeconds: 15
146           periodSeconds: 5
147         readinessProbe:
148           exec:
149             command: 
150             - /bin/sh
151             - -c
152             - {{ .Values.dbaas.probeTimeoutCommand }} {{ .Values.dbaas.probeTimeout }} redis-cli -p {{ include "common.serviceport.dbaas.redis" . }} ping
153           initialDelaySeconds: 15
154           periodSeconds: 5
155         ports:
156           - name: sentinel
157             containerPort: {{ include "common.serviceport.dbaas.sentinel" . }}
158         envFrom:
159         - configMapRef:
160             name: {{ include "common.configmapname.dbaas" . }}-appconfig
161         volumeMounts:
162         - mountPath: /data
163           name: data
164 {{- else }}
165           name: config
166 {{- end }}
167       volumes:
168       - name: config
169         configMap:
170           name: {{ template "common.configmapname.dbaas" . }}-config
171 {{- if $.Values.dbaas.enableHighAvailability }}
172       - name: data
173         emptyDir: {}
174 {{- end }}