forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubectl_options.go
34 lines (29 loc) · 923 Bytes
/
kubectl_options.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
package k8s
import "testing"
// Represents common options necessary to specify for all Kubectl calls
type KubectlOptions struct {
ContextName string
ConfigPath string
Namespace string
Env map[string]string
}
func NewKubectlOptions(contextName string, configPath string) *KubectlOptions {
return &KubectlOptions{
ContextName: contextName,
ConfigPath: configPath,
}
}
// GetConfigPath will return a sensible default if the config path is not set on the options.
func (kubectlOptions *KubectlOptions) GetConfigPath(t *testing.T) (string, error) {
// We predeclare `err` here so that we can update `kubeConfigPath` in the if block below. Otherwise, go complains
// saying `err` is undefined.
var err error
kubeConfigPath := kubectlOptions.ConfigPath
if kubeConfigPath == "" {
kubeConfigPath, err = GetKubeConfigPathE(t)
if err != nil {
return "", err
}
}
return kubeConfigPath, nil
}