forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
45 lines (39 loc) · 1.07 KB
/
util.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
43
44
45
package fixtures
import (
"io/ioutil"
"os"
"os/exec"
"strings"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
)
func runCli(diagnostics *Diagnostics, args []string) (string, error) {
runArgs := append([]string{"-n", Namespace}, args...)
cmd := exec.Command("../../dist/argo", runArgs...)
cmd.Env = os.Environ()
output, err := exec.Command("../../dist/argo", runArgs...).CombinedOutput()
stringOutput := string(output)
diagnostics.Log(log.Fields{"args": args, "output": stringOutput, "err": err}, "Run CLI")
return stringOutput, err
}
// LoadObject is used to load yaml to runtime.Object
func LoadObject(text string) (runtime.Object, error) {
var yaml string
if strings.HasPrefix(text, "@") {
file := strings.TrimPrefix(text, "@")
f, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
yaml = string(f)
} else {
yaml = text
}
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode([]byte(yaml), nil, nil)
if err != nil {
return nil, err
}
return obj, nil
}