Skip to content

K8SPS-465: add liveness and readiness probes to haproxy #975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions e2e-tests/tests/haproxy/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,97 @@ kind: StatefulSet
apiVersion: apps/v1
metadata:
name: haproxy-haproxy
spec:
template:
spec:
containers:
- args:
- haproxy
command:
- /opt/percona/haproxy-entrypoint.sh
env:
- name: CLUSTER_TYPE
value: async
- name: LIVENESS_CHECK_TIMEOUT
value: "30"
- name: READINESS_CHECK_TIMEOUT
value: "3"
image: perconalab/percona-server-mysql-operator:main-haproxy
imagePullPolicy: Always
livenessProbe:
exec:
command:
- /opt/percona/haproxy_liveness_check.sh
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 30
name: haproxy
ports:
- containerPort: 3306
name: mysql
protocol: TCP
- containerPort: 3307
name: mysql-replicas
protocol: TCP
- containerPort: 3309
name: proxy-protocol
protocol: TCP
- containerPort: 33060
name: mysqlx
protocol: TCP
readinessProbe:
exec:
command:
- /opt/percona/haproxy_readiness_check.sh
failureThreshold: 40
periodSeconds: 5
successThreshold: 10
timeoutSeconds: 3
resources:
requests:
cpu: 600m
memory: 1G
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/percona
name: bin
- mountPath: /etc/haproxy/mysql
name: haproxy-config
- mountPath: /etc/mysql/mysql-users-secret
name: users
- mountPath: /etc/mysql/mysql-tls-secret
name: tls
- mountPath: /etc/haproxy-custom/
name: config
- args:
- /opt/percona/peer-list
- -on-change=/opt/percona/haproxy_add_mysql_nodes.sh
- -service=$(MYSQL_SERVICE)
command:
- /opt/percona/haproxy-entrypoint.sh
env:
- name: MYSQL_SERVICE
value: haproxy-mysql-proxy
image: perconalab/percona-server-mysql-operator:main-haproxy
imagePullPolicy: Always
name: mysql-monit
resources:
requests:
cpu: 600m
memory: 1G
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/percona
name: bin
- mountPath: /etc/haproxy/mysql
name: haproxy-config
- mountPath: /etc/mysql/mysql-users-secret
name: users
- mountPath: /etc/mysql/mysql-tls-secret
name: tls
status:
observedGeneration: 1
replicas: 3
Expand Down
5 changes: 5 additions & 0 deletions e2e-tests/tests/haproxy/01-create-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ commands:
| yq eval '.spec.orchestrator.enabled=true' - \
| yq eval '.spec.proxy.haproxy.enabled=true' - \
| yq eval '.spec.proxy.haproxy.size=3' - \
| yq eval '.spec.proxy.haproxy.livenessProbe.timeoutSeconds=30' - \
| yq eval '.spec.proxy.haproxy.livenessProbe.periodSeconds=10' - \
| yq eval '.spec.proxy.haproxy.readinessProbe.failureThreshold=40' - \
| yq eval '.spec.proxy.haproxy.readinessProbe.successThreshold=10' - \
| yq eval '.spec.proxy.haproxy.size=3' - \
| kubectl -n "${NAMESPACE}" apply -f -
23 changes: 23 additions & 0 deletions pkg/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ func haproxyContainer(cr *apiv1alpha1.PerconaServerMySQL) corev1.Container {
}
env = append(env, spec.Env...)

readinessProbe := spec.ReadinessProbe
readinessProbe.Exec = &corev1.ExecAction{
Command: []string{"/opt/percona/haproxy_readiness_check.sh"},
}
livenessProbe := spec.LivenessProbe
livenessProbe.Exec = &corev1.ExecAction{
Command: []string{"/opt/percona/haproxy_liveness_check.sh"},
}

probsEnvs := []corev1.EnvVar{
{
Name: "LIVENESS_CHECK_TIMEOUT",
Value: fmt.Sprint(livenessProbe.TimeoutSeconds),
},
{
Name: "READINESS_CHECK_TIMEOUT",
Value: fmt.Sprint(readinessProbe.TimeoutSeconds),
},
}
env = append(env, probsEnvs...)

return corev1.Container{
Name: AppName,
Image: spec.Image,
Expand All @@ -300,6 +321,8 @@ func haproxyContainer(cr *apiv1alpha1.PerconaServerMySQL) corev1.Container {
EnvFrom: spec.EnvFrom,
Command: []string{"/opt/percona/haproxy-entrypoint.sh"},
Args: []string{"haproxy"},
ReadinessProbe: &readinessProbe,
LivenessProbe: &livenessProbe,
Ports: []corev1.ContainerPort{
{
Name: "mysql",
Expand Down
Loading