File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
2020 "bytes"
2121 "context"
2222 "strings"
23+ "time"
2324
2425 "github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
2526 corev1 "k8s.io/api/core/v1"
@@ -32,6 +33,11 @@ type Command interface {
3233 ExecCommandContainer (Context , string ) (string , string , error )
3334}
3435
36+ const (
37+ // ExecCommandTimeout defines the maximum duration allowed for a single container exec
38+ ExecCommandTimeout = 30 * time .Second
39+ )
40+
3541// ExecCommand runs command in the pod and returns buffer output.
3642func (clientsholder * ClientsHolder ) ExecCommandContainer (
3743 ctx Context , command string ) (stdout , stderr string , err error ) {
@@ -60,7 +66,11 @@ func (clientsholder *ClientsHolder) ExecCommandContainer(
6066 log .Error ("%v" , err )
6167 return stdout , stderr , err
6268 }
63- err = exec .StreamWithContext (context .TODO (), remotecommand.StreamOptions {
69+ // enforce an execution timeout for the remote command
70+ goCtx , cancel := context .WithTimeout (context .TODO (), ExecCommandTimeout )
71+ defer cancel ()
72+
73+ err = exec .StreamWithContext (goCtx , remotecommand.StreamOptions {
6474 Stdout : & buffOut ,
6575 Stderr : & buffErr ,
6676 })
You can’t perform that action at this time.
0 commit comments