Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1462 from cloudfoundry-incubator/f0rmiga/singleto…
Browse files Browse the repository at this point in the history
…n-database

refactor!: make database a singleton
  • Loading branch information
Vlad Iovanov authored Oct 8, 2020
2 parents b37167e + 8704f04 commit 888b997
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 127 deletions.
18 changes: 0 additions & 18 deletions chart/assets/scripts/jobs/pxc/active_passive_probe.sh

This file was deleted.

27 changes: 3 additions & 24 deletions chart/assets/scripts/jobs/pxc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,11 @@ fi
# shellcheck disable=SC1091
. /startup-scripts/functions.sh

ipaddr=$(hostname -i | awk ' { print $1 } ')
hostname=$(hostname)
echo "I AM $hostname - $ipaddr"

# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
CMDARG=( "$@" )
fi

cluster_join=$(resolveip -s "${K8S_SERVICE_NAME}" || echo "")
if [[ -z "${cluster_join}" ]]; then
echo "I am the Primary Node"
init_mysql
write_password_file
exec mysqld --user=mysql --wsrep_cluster_name="$SHORT_CLUSTER_NAME" --wsrep_node_name="$hostname" \
--wsrep_cluster_address=gcomm:// --wsrep_sst_method=xtrabackup-v2 \
--wsrep_sst_auth="xtrabackup:$XTRABACKUP_PASSWORD" \
--wsrep_node_address="$ipaddr" --pxc_strict_mode="$PXC_STRICT_MODE" "${CMDARG[@]}"
else
echo "I am not the Primary Node"
chown -R mysql:mysql /var/lib/mysql || true # default is root:root 777
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log
write_password_file
exec mysqld --user=mysql --wsrep_cluster_name="$SHORT_CLUSTER_NAME" --wsrep_node_name="$hostname" \
--wsrep_cluster_address="gcomm://$cluster_join" --wsrep_sst_method=xtrabackup-v2 \
--wsrep_sst_auth="xtrabackup:$XTRABACKUP_PASSWORD" \
--wsrep_node_address="$ipaddr" --pxc_strict_mode="$PXC_STRICT_MODE" "${CMDARG[@]}"
fi
init_mysql
write_password_file
exec mysqld --user=mysql --pxc_strict_mode="$PXC_STRICT_MODE" "${CMDARG[@]}"
7 changes: 7 additions & 0 deletions chart/config/unsupported.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ unsupported:
You are reusing an old and incompatible configuration, either via a values.yaml file from an
older release, or by using the --reuse-values option. Please start with a fresh configuration,
only changing settings relative to the defaults in the current release.
# Do not allow replicas for the database; doing this well in Kubernetes is
# more effort than we can expend, and is better handled by external databases.
sizing.database.instances: >
Database replicas are not supported.
KubeCF does not support highly available database configurations;
please use an external database instead.
5 changes: 1 addition & 4 deletions chart/templates/database/db-configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ data:
innodb_file_per_table = 1
innodb_autoinc_lock_mode=2
bind_address = 0.0.0.0
wsrep_slave_threads=2
wsrep_cluster_address=gcomm://
wsrep_provider=/usr/lib/galera3/libgalera_smm.so
wsrep_sst_method=xtrabackup-v2
wsrep_on = off
charset.cnf: |-
[client]
default_character_set = utf8
Expand Down
11 changes: 0 additions & 11 deletions chart/templates/database/db-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,5 @@ metadata:
spec:
type: password
secretName: var-pxc-password
---
apiVersion: quarks.cloudfoundry.org/v1alpha1
kind: QuarksSecret
metadata:
name: var-xtrabackup-password
namespace: {{ .Release.Namespace | quote }}
labels:
{{- list . "database" | include "component.labels" | nindent 4 }}
spec:
type: password
secretName: var-xtrabackup-password

{{- end }}{{/* .Values.features.embedded_database.enabled */}}
20 changes: 0 additions & 20 deletions chart/templates/database/db-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,5 @@ spec:
targetPort: mysql
selector:
{{- list . "database" | include "component.selector" | nindent 4 }}
quarks.cloudfoundry.org/pod-active: active
---
apiVersion: v1
kind: Service
metadata:
name: database-repl
namespace: {{ .Release.Namespace | quote }}
labels:
{{- list . "database" | include "component.labels" | nindent 4 }}
spec:
clusterIP: None
ports:
- name: galera
port: 4567
- name: state-xfer
port: 4568
- name: state-snap
port: 4444
selector:
{{- list . "database" | include "component.selector" | nindent 4 }}

{{- end }}{{/* .Values.features.embedded_database.enabled */}}
55 changes: 6 additions & 49 deletions chart/templates/database/db-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,19 @@ metadata:
{{- list . "database" | include "component.labels" | nindent 4 }}
spec:
updateOnConfigChange: true
activePassiveProbes:
database:
periodSeconds: 5
exec:
command:
- /bin/bash
- -c
- |
{{- .Files.Get "assets/scripts/jobs/pxc/active_passive_probe.sh" | nindent 12 }}
template:
metadata:
name: database
namespace: {{ .Release.Namespace | quote }}
labels:
{{- list . "database" | include "component.labels" | nindent 8 }}
spec:
{{- $replicas := 1 }}
{{- if $.Values.sizing.database.instances }}
{{- $replicas = $.Values.sizing.database.instances }}
{{- else if $.Values.high_availability }}
{{- $replicas = 3 }}
{{- end }}
{{- if eq (mod $replicas 2) 0 }}
{{- include "_config.fail" "The number of database instances must be odd to avoid split-brain" }}
{{- end }}
replicas: {{ $replicas }}
# Database replicas are not allowed.
# High-availability is not currently feasible to support in k8s.
# Galera replication on rolling updates of the statefulset is hard to get
# right and to maintain as part of KubeCF. For an HA database, prefer
# using a specialized external one.
replicas: 1
selector:
matchLabels:
{{- list . "database" | include "component.selector" | nindent 10 }}
Expand All @@ -47,19 +34,6 @@ spec:
spec:
{{- if $.Values.sizing.database.affinity }}
affinity: {{ $.Values.sizing.database.affinity | toJson }}
{{- else }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: quarks.cloudfoundry.org/quarks-statefulset-name
operator: In
values:
- database
topologyKey: kubernetes.io/hostname
{{- end }}
initContainers:
- name: remove-lost-found
Expand Down Expand Up @@ -89,30 +63,13 @@ spec:
secretKeyRef:
name: var-pxc-password
key: password
- name: XTRABACKUP_PASSWORD
valueFrom:
secretKeyRef:
name: var-xtrabackup-password
key: password
- name: ALLOW_ROOT_FROM
value: "%"
- name: CLUSTER_NAME
value: {{ .Release.Name }}-database
- name: SHORT_CLUSTER_NAME
value: {{ .Release.Name }}-database
- name: K8S_SERVICE_NAME
value: database-repl
- name: PXC_STRICT_MODE
value: ENFORCING
ports:
- name: mysql
containerPort: 3306
- name: galera-repl
containerPort: 4567
- name: state-transfer
containerPort: 4568
- name: state-snapshot
containerPort: 4444
livenessProbe:
exec:
command:
Expand Down
1 change: 0 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ sizing:
credhub:
instances: ~
database:
instances: ~
persistence:
size: 20Gi
diego_api:
Expand Down

0 comments on commit 888b997

Please sign in to comment.