--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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
+appVersion: "1.0"
+description: DBaaS with high availability
+name: dbaasha
+version: 1.1.0
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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. #
+################################################################################
+
+dependencies:
+ - name: ric-common
+ version: ~3.0.0
+ repository: "@local"
+ #- name: dbaasha
+ # condition: dbaasha.enabled
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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. #
+################################################################################
+{{- $fullName := include "common.fullname.dbaasha" . }}
+{{- $podName := include "common.statefulsetname.dbaasha" . }}
+{{- $appName := include "common.name.dbaasha" . }}
+{{- $platformName := include "common.namespace.platform" . }}
+{{- $replicas := int .Values.dbaasha.replicas }}
+{{- $redisPort := include "common.serviceport.dbaasha.redis" .}}
+{{- $sentinelPort := include "common.serviceport.dbaasha.sentinel" .}}
+{{- $root := . }}
+{{- range $i := until $replicas }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ $fullName }}-announce-{{ $i }}
+ labels:
+ app: {{ $platformName }}-{{ $appName }}
+ chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version | replace "+" "_" }}
+ release: {{ $root.Release.Name }}
+ heritage: {{ $root.Release.Service }}
+spec:
+ publishNotReadyAddresses: true
+ type: ClusterIP
+ ports:
+ - name: server
+ port: {{ $redisPort }}
+ protocol: TCP
+ targetPort: redis
+ - name: sentinel
+ port: {{ $sentinelPort }}
+ protocol: TCP
+ targetPort: sentinel
+ selector:
+ release: {{ $root.Release.Name }}
+ app: {{ $platformName }}-{{ $appName }}
+ "statefulset.kubernetes.io/pod-name": {{ $podName }}-server-{{ $i }}
+{{- end }}
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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: {{ template "common.configmapname.dbaasha" . }}-appconfig
+ labels:
+ heritage: {{ .Release.Service }}
+ release: {{ .Release.Name }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version }}
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+data:
+ DBAAS_SERVICE_HOST: {{ include "common.servicename.dbaasha.tcp" . }}.{{ .Release.Namespace }}.svc.cluster.local
+ DBAAS_SERVICE_PORT: {{ include "common.serviceport.dbaasha.redis" . | quote }}
+ DBAAS_SERVICE_SENTINEL_PORT: {{ include "common.serviceport.dbaasha.sentinel" . | quote }}
+ DBAAS_MASTER_NAME: {{ .Values.dbaasha.redis.masterGroupName }}
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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: {{ template "common.configmapname.dbaasha" . }}-config
+ labels:
+ heritage: {{ .Release.Service }}
+ release: {{ .Release.Name }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version }}
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+data:
+ redis.conf: |
+ dir "/data"
+ {{- range $key, $value := .Values.dbaasha.redis.config }}
+ {{ $key }} {{ $value }}
+ {{- end }}
+
+ sentinel.conf: |
+ dir "/data"
+ {{- $root := . -}}
+ {{- range $key, $value := .Values.dbaasha.sentinel.config }}
+ sentinel {{ $key }} {{ $root.Values.dbaasha.redis.masterGroupName }} {{ $value }}
+ {{- end }}
+ protected-mode {{ index .Values.dbaasha.sentinel "protected-mode" }}
+
+ init.sh: |
+ HOSTNAME="$(hostname)"
+ INDEX="${HOSTNAME##*-}"
+ MASTER="$(redis-cli -h {{ template "common.servicename.dbaasha.tcp" . }}.{{ .Release.Namespace }}.svc.cluster.local -p {{ include "common.serviceport.dbaasha.sentinel" . }} sentinel get-master-addr-by-name {{ .Values.dbaasha.redis.masterGroupName }} | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
+ MASTER_GROUP="{{ .Values.dbaasha.redis.masterGroupName }}"
+ QUORUM="{{ .Values.dbaasha.sentinel.quorum }}"
+ REDIS_CONF=/data/conf/redis.conf
+ REDIS_PORT={{ include "common.serviceport.dbaasha.redis" . }}
+ SENTINEL_CONF=/data/conf/sentinel.conf
+ SENTINEL_PORT={{ include "common.serviceport.dbaasha.sentinel" . }}
+ SERVICE={{ template "common.fullname.dbaasha" . }}
+ set -eu
+
+ sentinel_update() {
+ echo "Updating sentinel config"
+ sed -i "1s/^/$(cat sentinel-id)\\n/" "$SENTINEL_CONF"
+ sed -i "2s/^/sentinel monitor $MASTER_GROUP $1 $REDIS_PORT $QUORUM \\n/" "$SENTINEL_CONF"
+ echo "sentinel announce-ip $ANNOUNCE_IP" >> $SENTINEL_CONF
+ echo "sentinel announce-port $SENTINEL_PORT" >> $SENTINEL_CONF
+ }
+
+ redis_update() {
+ echo "Updating redis config"
+ echo "slaveof $1 $REDIS_PORT" >> "$REDIS_CONF"
+ echo "slave-announce-ip $ANNOUNCE_IP" >> $REDIS_CONF
+ echo "slave-announce-port $REDIS_PORT" >> $REDIS_CONF
+ }
+
+ redis_master_update() {
+ echo "Updating redis default master config"
+ echo "slave-announce-ip $ANNOUNCE_IP" >> $REDIS_CONF
+ echo "slave-announce-port $REDIS_PORT" >> $REDIS_CONF
+ }
+
+ copy_config() {
+ if [ -f "$SENTINEL_CONF" ]; then
+ grep "sentinel myid" "$SENTINEL_CONF" > sentinel-id || true
+ fi
+ cp /readonly-config/redis.conf "$REDIS_CONF"
+ cp /readonly-config/sentinel.conf "$SENTINEL_CONF"
+ }
+
+ setup_defaults() {
+ echo "Setting up defaults"
+ if [ "$INDEX" = "0" ]; then
+ echo "Setting this pod as the default master"
+ sed -i "s/^.*slaveof.*//" "$REDIS_CONF"
+ redis_master_update
+ sentinel_update "$ANNOUNCE_IP"
+ else
+ DEFAULT_MASTER="$(getent hosts "$SERVICE-announce-0" | awk '{ print $1 }')"
+ if [ -z "$DEFAULT_MASTER" ]; then
+ echo "Unable to resolve host"
+ exit 1
+ fi
+ echo "Setting default slave config.."
+ redis_update "$DEFAULT_MASTER"
+ sentinel_update "$DEFAULT_MASTER"
+ fi
+ }
+
+ find_master() {
+ echo "Attempting to find master"
+ if [ "$(redis-cli -h "$MASTER"{{ if .Values.auth }} -a "$AUTH"{{ end }} ping)" != "PONG" ]; then
+ echo "Can't ping master, attempting to force failover"
+ if redis-cli -h "$SERVICE" -p "$SENTINEL_PORT" sentinel failover "$MASTER_GROUP" | grep -q 'NOGOODSLAVE' ; then
+ setup_defaults
+ return 0
+ fi
+ sleep 10
+ MASTER="$(redis-cli -h $SERVICE -p $SENTINEL_PORT sentinel get-master-addr-by-name $MASTER_GROUP | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
+ if [ "$MASTER" ]; then
+ sentinel_update "$MASTER"
+ redis_update "$MASTER"
+ else
+ echo "Could not failover, exiting..."
+ exit 1
+ fi
+ else
+ echo "Found reachable master, updating config"
+ sentinel_update "$MASTER"
+ redis_update "$MASTER"
+ fi
+ }
+
+ mkdir -p /data/conf/
+
+ echo "Initializing config.."
+ copy_config
+
+ ANNOUNCE_IP=$(getent hosts "$SERVICE-announce-$INDEX" | awk '{ print $1 }')
+ if [ -z "$ANNOUNCE_IP" ]; then
+ "Could not resolve the announce ip for this pod"
+ exit 1
+ elif [ "$MASTER" ]; then
+ find_master
+ else
+ setup_defaults
+ fi
+
+ if [ "${AUTH:-}" ]; then
+ echo "Setting auth values"
+ sed -i "s/replace-default-auth/$AUTH/" "$REDIS_CONF" "$SENTINEL_CONF"
+ fi
+
+ echo "Ready..."
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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: {{ template "common.configmapname.dbaasha" . }}-probes
+ labels:
+ heritage: {{ .Release.Service }}
+ release: {{ .Release.Name }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version }}
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+data:
+ readiness.sh: |
+ #!/bin/sh
+ set -eu
+ CHECK_SERVER="$(timeout -t "$2" redis-cli -p "$1"{{ if .Values.auth }} -a "$AUTH"{{ end }} ping)"
+
+ if [ "$CHECK_SERVER" != "PONG" ]; then
+ echo "Server check failed with: $CHECK_SERVER"
+ exit 1
+ fi
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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: Service
+metadata:
+ name: {{ include "common.servicename.dbaasha.tcp" . }}
+ labels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ type: ClusterIP
+ clusterIP: None
+ ports:
+ - name: server
+ port: {{ include "common.serviceport.dbaasha.redis" . }}
+ protocol: TCP
+ targetPort: redis
+ - name: sentinel
+ port: {{ include "common.serviceport.dbaasha.sentinel" . }}
+ protocol: TCP
+ targetPort: sentinel
+ selector:
+ release: {{ .Release.Name }}
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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. #
+################################################################################
+{{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaasha.image.registry }}
+---
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+ name: {{ include "common.statefulsetname.dbaasha" . }}-server
+ namespace: {{ include "common.namespace.platform" . }}
+ labels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ selector:
+ matchLabels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ release: {{ .Release.Name }}
+ serviceName: {{ template "common.servicename.dbaasha.tcp" . }}
+ replicas: {{ .Values.dbaasha.replicas }}
+ podManagementPolicy: OrderedReady
+ updateStrategy:
+ type: RollingUpdate
+ template:
+ metadata:
+ labels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ release: {{ .Release.Name }}
+ spec:
+ {{- if .Values.dbaasha.nodeSelector }}
+ nodeSelector:
+{{ toYaml .Values.dbaasha.nodeSelector | indent 8 }}
+ {{- end }}
+ {{- with .Values.dbaasha.affinity }}
+ affinity:
+{{ tpl . $ | indent 8 }}
+ {{- end }}
+ imagePullSecrets:
+ {{- $ctx := dict "ctx" . "defaultregistry" .Values.dbaasha.image.registry }}
+ - name: {{ include "common.dockerregistry.credential" $ctx }}
+ 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 }}
+ imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx }}
+ command:
+ - sh
+ args:
+ - /readonly-config/init.sh
+ volumeMounts:
+ - name: config
+ mountPath: /readonly-config
+ readOnly: true
+ - name: data
+ mountPath: /data
+ containers:
+ - name: {{ include "common.containername.dbaasha.redis" . }}
+ image: {{ include "common.dockerregistry.url" $ctx }}/{{ .Values.dbaasha.image.name }}:{{ .Values.dbaasha.image.tag }}
+ imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx }}
+ command:
+ - redis-server
+ args:
+ - /data/conf/redis.conf
+ livenessProbe:
+ exec:
+ command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+ initialDelaySeconds: 15
+ periodSeconds: 5
+ readinessProbe:
+ exec:
+ command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+ initialDelaySeconds: 15
+ periodSeconds: 5
+ ports:
+ - name: redis
+ containerPort: {{ include "common.serviceport.dbaasha.redis" . }}
+ volumeMounts:
+ - mountPath: /data
+ 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 }}
+ imagePullPolicy: {{ include "common.dockerregistry.pullpolicy" $ctx }}
+ command:
+ - redis-server
+ args:
+ - /data/conf/sentinel.conf
+ - --sentinel
+ livenessProbe:
+ exec:
+ command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+ initialDelaySeconds: 15
+ periodSeconds: 5
+ readinessProbe:
+ exec:
+ command: [ "sh", "/probes/readiness.sh", {{ include "common.serviceport.dbaasha.redis" . | quote }}, {{ .Values.dbaasha.probeTimeout | quote }}]
+ initialDelaySeconds: 15
+ periodSeconds: 5
+ ports:
+ - name: sentinel
+ containerPort: {{ include "common.serviceport.dbaasha.sentinel" . }}
+ volumeMounts:
+ - mountPath: /data
+ name: data
+ - mountPath: /probes
+ name: probes
+ 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: data
+ emptyDir: {}
--- /dev/null
+################################################################################
+# Copyright (c) 2019 AT&T Intellectual Property. #
+# Copyright (c) 2019 Nokia. #
+# #
+# 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. #
+################################################################################
+
+dbaasha:
+ image:
+ registry: "nexus3.o-ran-sc.org:10002/o-ran-sc"
+ name: ric-plt-dbaas
+ tag: 0.2.2
+ imagePullPolicy: IfNotPresent
+ replicas: 3
+ enabled: true
+ sysctlImage:
+ enabled: true
+ command:
+ - /bin/sh
+ - -c
+ - |-
+ sysctl -w net.core.somaxconn=511
+ echo never > /host-sys/kernel/mm/transparent_hugepage/enabled
+ mountHostSys: true
+ probeTimeout: 10
+ redis:
+ masterGroupName: dbaasmaster
+ config:
+ ## For /data/conf/redis.conf
+ min-slaves-to-write: 1
+ min-slaves-max-lag: 5
+ maxmemory: "0"
+ maxmemory-policy: "volatile-lru"
+ protected-mode: "no"
+ loadmodule: "/usr/local/libexec/redismodule/libredismodule.so"
+ sentinel:
+ quorum: 2
+ protected-mode: "no"
+ config:
+ ## For /data/conf/sentinel.conf
+ down-after-milliseconds: 5000
+ failover-timeout: 60000
+ parallel-syncs: 1
+ affinity: |
+ podAntiAffinity:
+ requiredDuringSchedulingIgnoredDuringExecution:
+ - labelSelector:
+ matchLabels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ release: {{ .Release.Name }}
+ topologyKey: kubernetes.io/hostname
+ preferredDuringSchedulingIgnoredDuringExecution:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchLabels:
+ app: {{ include "common.namespace.platform" . }}-{{ include "common.name.dbaasha" . }}
+ release: {{ .Release.Name }}
+ topologyKey: failure-domain.beta.kubernetes.io/zone