-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
cmd.go
59 lines (51 loc) · 1.89 KB
/
cmd.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package helm
import (
"testing"
"github.com/gruntwork-io/gruntwork-cli/errors"
"github.com/gruntwork-io/terratest/modules/shell"
)
// getCommonArgs extracts common helm options. In this case, these are:
// - kubeconfig path
// - kubeconfig context
// - helm home path
func getCommonArgs(options *Options, args ...string) []string {
if options.KubectlOptions != nil && options.KubectlOptions.ContextName != "" {
args = append(args, "--kube-context", options.KubectlOptions.ContextName)
}
if options.KubectlOptions != nil && options.KubectlOptions.ConfigPath != "" {
args = append(args, "--kubeconfig", options.KubectlOptions.ConfigPath)
}
if options.HomePath != "" {
args = append(args, "--home", options.HomePath)
}
return args
}
// getValuesArgsE computes the args to pass in for setting values
func getValuesArgsE(t *testing.T, options *Options, args ...string) ([]string, error) {
args = append(args, formatSetValuesAsArgs(options.SetValues, "--set")...)
args = append(args, formatSetValuesAsArgs(options.SetStrValues, "--set-string")...)
valuesFilesArgs, err := formatValuesFilesAsArgsE(t, options.ValuesFiles)
if err != nil {
return args, errors.WithStackTrace(err)
}
args = append(args, valuesFilesArgs...)
setFilesArgs, err := formatSetFilesAsArgsE(t, options.SetFiles)
if err != nil {
return args, errors.WithStackTrace(err)
}
args = append(args, setFilesArgs...)
return args, nil
}
// RunHelmCommandAndGetOutputE runs helm with the given arguments and options and returns stdout/stderr.
func RunHelmCommandAndGetOutputE(t *testing.T, options *Options, cmd string, additionalArgs ...string) (string, error) {
args := []string{cmd}
args = getCommonArgs(options, args...)
args = append(args, additionalArgs...)
helmCmd := shell.Command{
Command: "helm",
Args: args,
WorkingDir: ".",
Env: options.EnvVars,
}
return shell.RunCommandAndGetOutputE(t, helmCmd)
}