Skip to content

Commit 2f959a7

Browse files
authored
Merge pull request #702 from karlhungus/output_stderr_allow_timeout_setting
output stdout and stderr from custom commands, allow setting timeout for critctl
2 parents 7bd6e85 + b6d8069 commit 2f959a7

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Diff for: cmd/healthchecker/options/options.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type HealthCheckerOptions struct {
3939
EnableRepair bool
4040
CriCtlPath string
4141
CriSocketPath string
42+
CriTimeout time.Duration
4243
CoolDownTime time.Duration
4344
LoopBackTime time.Duration
4445
HealthCheckTimeout time.Duration
@@ -62,6 +63,8 @@ func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
6263
"The path to the crictl binary. This is used to check health of cri component.")
6364
fs.StringVar(&hco.CriSocketPath, "cri-socket-path", types.DefaultCriSocketPath,
6465
"The path to the cri socket. Used with crictl to specify the socket path.")
66+
fs.DurationVar(&hco.CriTimeout, "cri-timeout", types.DefaultCriTimeout,
67+
"The duration to wait for crictl to run.")
6568
fs.DurationVar(&hco.CoolDownTime, "cooldown-time", types.DefaultCoolDownTime,
6669
"The duration to wait for the service to be up before attempting repair.")
6770
fs.DurationVar(&hco.LoopBackTime, "loopback-time", types.DefaultLoopBackTime,

Diff for: pkg/healthchecker/health_checker.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error)
150150
}
151151
case types.CRIComponent:
152152
return func() (bool, error) {
153-
if _, err := execCommand(hco.HealthCheckTimeout, hco.CriCtlPath, "--runtime-endpoint="+hco.CriSocketPath, "pods", "--latest"); err != nil {
153+
if _, err := execCommand(hco.HealthCheckTimeout, hco.CriCtlPath, "--timeout="+hco.CriTimeout.String()+"--runtime-endpoint="+hco.CriSocketPath, "pods", "--latest"); err != nil {
154154
return false, nil
155155
}
156156
return true, nil
@@ -167,10 +167,11 @@ func execCommand(timeout time.Duration, command string, args ...string) (string,
167167
ctx, cancel := context.WithTimeout(context.Background(), timeout)
168168
defer cancel()
169169
cmd := exec.CommandContext(ctx, command, args...)
170-
out, err := cmd.Output()
170+
out, err := cmd.CombinedOutput()
171171
if err != nil {
172172
glog.Infof("command %v failed: %v, %v\n", cmd, err, out)
173173
return "", err
174174
}
175+
175176
return strings.TrimSuffix(string(out), "\n"), nil
176177
}

Diff for: pkg/healthchecker/types/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
const (
2828
DefaultLoopBackTime = 0 * time.Minute
29+
DefaultCriTimeout = 2 * time.Second
2930
DefaultCoolDownTime = 2 * time.Minute
3031
DefaultHealthCheckTimeout = 10 * time.Second
3132
CmdTimeout = 10 * time.Second

0 commit comments

Comments
 (0)