From 72946108e5d23ab5cba6a69401aa5e8deb166eb0 Mon Sep 17 00:00:00 2001 From: motorailgun <28751910+motorailgun@users.noreply.github.com> Date: Wed, 24 Aug 2022 12:00:57 +0900 Subject: [PATCH] operator: improve ProbeHandler error message This commit implements more diagnostic error for unsccessful Liveness- and Readiness-Probe of Pods. Added codes are expected to catch failures of `ceph status` and `ceph mon_status`, and report it. Closes: https://github.com/rook/rook/issues/9846 Closes: https://github.com/rook/rook/issues/9852 Signed-off-by: motorailgun Signed-off-by: Satoru Takeuchi (cherry picked from commit ff0951738fcd2479c53d6b1ac472b5176530f028) --- pkg/operator/ceph/controller/spec.go | 13 ++++++++++++- pkg/operator/ceph/controller/spec_test.go | 9 +++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/operator/ceph/controller/spec.go b/pkg/operator/ceph/controller/spec.go index 6cea7c79d..bad9e59e7 100644 --- a/pkg/operator/ceph/controller/spec.go +++ b/pkg/operator/ceph/controller/spec.go @@ -570,12 +570,23 @@ func GenerateLivenessProbeExecDaemon(daemonType, daemonID string) *v1.Probe { // // Example: // env -i sh -c "ceph --admin-daemon /run/ceph/ceph-osd.0.asok status" + // + // Ceph gives pretty un-diagnostic error message when `ceph status` or `ceph mon_status` command fails. + // Add a clear message after Ceph's to help. + // ref: https://github.com/rook/rook/issues/9846 Command: []string{ "env", "-i", "sh", "-c", - fmt.Sprintf("ceph --admin-daemon %s %s", confDaemon.buildSocketPath(), confDaemon.buildAdminSocketCommand()), + fmt.Sprintf(`outp="$(ceph --admin-daemon %s %s 2>&1)" +rc=$? +if [ $rc -ne 0 ]; then + echo "ceph daemon health check failed with the following output:" + echo "$outp" | sed -e 's/^/> /g' + exit $rc +fi`, + confDaemon.buildSocketPath(), confDaemon.buildAdminSocketCommand()), }, }, }, diff --git a/pkg/operator/ceph/controller/spec_test.go b/pkg/operator/ceph/controller/spec_test.go index e1203032f..f75ce631f 100644 --- a/pkg/operator/ceph/controller/spec_test.go +++ b/pkg/operator/ceph/controller/spec_test.go @@ -153,8 +153,13 @@ func TestGenerateLivenessProbeExecDaemon(t *testing.T) { "-i", "sh", "-c", - "ceph --admin-daemon /run/ceph/ceph-osd.0.asok status", - } + `outp="$(ceph --admin-daemon /run/ceph/ceph-osd.0.asok status 2>&1)" +rc=$? +if [ $rc -ne 0 ]; then + echo "ceph daemon health check failed with the following output:" + echo "$outp" | sed -e 's/^/> /g' + exit $rc +fi`} assert.Equal(t, expectedCommand, probe.ProbeHandler.Exec.Command) assert.Equal(t, livenessProbeInitialDelaySeconds, probe.InitialDelaySeconds)