diff --git a/e2e-tests/tests/haproxy/01-assert.yaml b/e2e-tests/tests/haproxy/01-assert.yaml index 59cb5e01f..97730f1d7 100644 --- a/e2e-tests/tests/haproxy/01-assert.yaml +++ b/e2e-tests/tests/haproxy/01-assert.yaml @@ -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 diff --git a/e2e-tests/tests/haproxy/01-create-cluster.yaml b/e2e-tests/tests/haproxy/01-create-cluster.yaml index ede15a7d3..518463c15 100644 --- a/e2e-tests/tests/haproxy/01-create-cluster.yaml +++ b/e2e-tests/tests/haproxy/01-create-cluster.yaml @@ -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 - diff --git a/pkg/haproxy/haproxy.go b/pkg/haproxy/haproxy.go index 052e522e2..93f1a648c 100644 --- a/pkg/haproxy/haproxy.go +++ b/pkg/haproxy/haproxy.go @@ -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, @@ -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",