Skip to content

Commit b90ada1

Browse files
egeguneshors
andauthored
K8SPS-285: Add startup probe for router (#360)
Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 2ea88df commit b90ada1

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

api/v1alpha1/perconaservermysql_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,22 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(ctx context.Context, serverVersi
508508
cr.Spec.Proxy.Router = new(MySQLRouterSpec)
509509
}
510510

511+
if cr.Spec.Proxy.Router.StartupProbe.InitialDelaySeconds == 0 {
512+
cr.Spec.Proxy.Router.StartupProbe.InitialDelaySeconds = 5
513+
}
514+
if cr.Spec.Proxy.Router.StartupProbe.PeriodSeconds == 0 {
515+
cr.Spec.Proxy.Router.StartupProbe.PeriodSeconds = 5
516+
}
517+
if cr.Spec.Proxy.Router.StartupProbe.FailureThreshold == 0 {
518+
cr.Spec.Proxy.Router.StartupProbe.FailureThreshold = 1
519+
}
520+
if cr.Spec.Proxy.Router.StartupProbe.SuccessThreshold == 0 {
521+
cr.Spec.Proxy.Router.StartupProbe.SuccessThreshold = 1
522+
}
523+
if cr.Spec.Proxy.Router.StartupProbe.TimeoutSeconds == 0 {
524+
cr.Spec.Proxy.Router.StartupProbe.TimeoutSeconds = 3
525+
}
526+
511527
if cr.Spec.Proxy.Router.ReadinessProbe.PeriodSeconds == 0 {
512528
cr.Spec.Proxy.Router.ReadinessProbe.PeriodSeconds = 5
513529
}

build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ COPY build/ps-entrypoint.sh /opt/percona-server-mysql-operator/ps-entrypoint.sh
8888
COPY build/heartbeat-entrypoint.sh /opt/percona-server-mysql-operator/heartbeat-entrypoint.sh
8989
COPY build/router-entrypoint.sh /opt/percona-server-mysql-operator/router-entrypoint.sh
9090
COPY build/router_readiness_check.sh /opt/percona-server-mysql-operator/router_readiness_check.sh
91+
COPY build/router_startup_check.sh /opt/percona-server-mysql-operator/router_startup_check.sh
9192
COPY build/orc-entrypoint.sh /opt/percona-server-mysql-operator/orc-entrypoint.sh
9293
COPY build/orchestrator.conf.json /opt/percona-server-mysql-operator/orchestrator.conf.json
9394
COPY build/ps-init-entrypoint.sh /opt/percona-server-mysql-operator/ps-init-entrypoint.sh

build/ps-init-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/orchestrator.conf
1414

1515
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/router-entrypoint.sh" "${BINDIR}/router-entrypoint.sh"
1616
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/router_readiness_check.sh" "${BINDIR}/router_readiness_check.sh"
17+
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/router_startup_check.sh" "${BINDIR}/router_startup_check.sh"
1718

1819
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/bootstrap" "${BINDIR}/bootstrap"
1920
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D "${OPERATORDIR}/healthcheck" "${BINDIR}/healthcheck"

build/router_startup_check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
OPERATOR_PASS=$(</etc/mysql/mysql-users-secret/operator)
4+
5+
if [[ $(curl -k -s -u operator:"${OPERATOR_PASS}" -o /dev/null -w %{http_code} https://localhost:8443/api/20190715/router/status) != 200 ]]; then
6+
echo "Router is not ready"
7+
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
timeout: 30
4+
---
5+
kind: ConfigMap
6+
apiVersion: v1
7+
metadata:
8+
name: 02-write-data
9+
data:
10+
data: "100500"

e2e-tests/tests/gr-bootstrap/02-write-data.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ commands:
1414
run_mysql \
1515
"INSERT myDB.myTable (id) VALUES (100500)" \
1616
"-h $(get_mysql_router_service $(get_cluster_name)) -P 6446 -uroot -proot_password"
17+
18+
data=$(run_mysql "SELECT * FROM myDB.myTable" "-h $(get_mysql_router_service $(get_cluster_name)) -P 6446 -uroot -proot_password")
19+
20+
kubectl create configmap -n "${NAMESPACE}" 02-write-data --from-literal=data="${data}"

pkg/router/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func routerContainer(cr *apiv1alpha1.PerconaServerMySQL) corev1.Container {
304304
TerminationMessagePath: "/dev/termination-log",
305305
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
306306
SecurityContext: spec.ContainerSecurityContext,
307+
StartupProbe: k8s.ExecProbe(spec.StartupProbe, []string{"/opt/percona/router_startup_check.sh"}),
307308
ReadinessProbe: k8s.ExecProbe(spec.ReadinessProbe, []string{"/opt/percona/router_readiness_check.sh"}),
308309
}
309310
}

0 commit comments

Comments
 (0)