forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.go
42 lines (34 loc) · 876 Bytes
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package exec
import (
"fmt"
"os"
"os/exec"
"time"
argoexec "github.com/argoproj/pkg/exec"
tracing "github.com/argoproj/argo-cd/util/tracing"
)
var timeout time.Duration
func init() {
initTimeout()
}
func initTimeout() {
var err error
timeout, err = time.ParseDuration(os.Getenv("ARGOCD_EXEC_TIMEOUT"))
if err != nil {
timeout = 90 * time.Second
}
}
func Run(cmd *exec.Cmd) (string, error) {
return RunWithRedactor(cmd, nil)
}
func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string, error) {
span := tracing.StartSpan(fmt.Sprintf("exec %v", cmd.Args[0]))
span.SetBaggageItem("dir", fmt.Sprintf("%v", cmd.Dir))
span.SetBaggageItem("args", fmt.Sprintf("%v", cmd.Args))
defer span.Finish()
opts := argoexec.CmdOpts{Timeout: timeout}
if redactor != nil {
opts.Redactor = redactor
}
return argoexec.RunCommandExt(cmd, opts)
}