From 6de3fabc9f758ead5a7602039d63df6ccd2ba577 Mon Sep 17 00:00:00 2001 From: "Izaak Alpert (karlhungus)" Date: Thu, 15 Sep 2022 14:31:24 -0400 Subject: [PATCH 1/2] output stdout and stderr from custom commands --- pkg/healthchecker/health_checker.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/healthchecker/health_checker.go b/pkg/healthchecker/health_checker.go index 1273ff99d..ad6615bb5 100644 --- a/pkg/healthchecker/health_checker.go +++ b/pkg/healthchecker/health_checker.go @@ -167,10 +167,11 @@ func execCommand(timeout time.Duration, command string, args ...string) (string, ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() cmd := exec.CommandContext(ctx, command, args...) - out, err := cmd.Output() + out, err := cmd.CombinedOutput() if err != nil { glog.Infof("command %v failed: %v, %v\n", cmd, err, out) return "", err } + return strings.TrimSuffix(string(out), "\n"), nil } From b6d806961062a20981d8530f25b79f5452523c0d Mon Sep 17 00:00:00 2001 From: "Izaak Alpert (karlhungus)" Date: Thu, 15 Sep 2022 14:31:41 -0400 Subject: [PATCH 2/2] allow setting crictl timeout --- cmd/healthchecker/options/options.go | 3 +++ pkg/healthchecker/health_checker.go | 2 +- pkg/healthchecker/types/types.go | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/healthchecker/options/options.go b/cmd/healthchecker/options/options.go index 128c44d44..5711fc324 100644 --- a/cmd/healthchecker/options/options.go +++ b/cmd/healthchecker/options/options.go @@ -39,6 +39,7 @@ type HealthCheckerOptions struct { EnableRepair bool CriCtlPath string CriSocketPath string + CriTimeout time.Duration CoolDownTime time.Duration LoopBackTime time.Duration HealthCheckTimeout time.Duration @@ -62,6 +63,8 @@ func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) { "The path to the crictl binary. This is used to check health of cri component.") fs.StringVar(&hco.CriSocketPath, "cri-socket-path", types.DefaultCriSocketPath, "The path to the cri socket. Used with crictl to specify the socket path.") + fs.DurationVar(&hco.CriTimeout, "cri-timeout", types.DefaultCriTimeout, + "The duration to wait for crictl to run.") fs.DurationVar(&hco.CoolDownTime, "cooldown-time", types.DefaultCoolDownTime, "The duration to wait for the service to be up before attempting repair.") fs.DurationVar(&hco.LoopBackTime, "loopback-time", types.DefaultLoopBackTime, diff --git a/pkg/healthchecker/health_checker.go b/pkg/healthchecker/health_checker.go index ad6615bb5..5856766d7 100644 --- a/pkg/healthchecker/health_checker.go +++ b/pkg/healthchecker/health_checker.go @@ -150,7 +150,7 @@ func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error) } case types.CRIComponent: return func() (bool, error) { - if _, err := execCommand(hco.HealthCheckTimeout, hco.CriCtlPath, "--runtime-endpoint="+hco.CriSocketPath, "pods", "--latest"); err != nil { + if _, err := execCommand(hco.HealthCheckTimeout, hco.CriCtlPath, "--timeout="+hco.CriTimeout.String()+"--runtime-endpoint="+hco.CriSocketPath, "pods", "--latest"); err != nil { return false, nil } return true, nil diff --git a/pkg/healthchecker/types/types.go b/pkg/healthchecker/types/types.go index 02523f6b3..97039f03d 100644 --- a/pkg/healthchecker/types/types.go +++ b/pkg/healthchecker/types/types.go @@ -26,6 +26,7 @@ import ( const ( DefaultLoopBackTime = 0 * time.Minute + DefaultCriTimeout = 2 * time.Second DefaultCoolDownTime = 2 * time.Minute DefaultHealthCheckTimeout = 10 * time.Second CmdTimeout = 10 * time.Second