github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/kubectl_options.go (about) 1 package k8s 2 3 import ( 4 "github.com/terraform-modules-krish/terratest/modules/testing" 5 ) 6 7 // KubectlOptions represents common options necessary to specify for all Kubectl calls 8 type KubectlOptions struct { 9 ContextName string 10 ConfigPath string 11 Namespace string 12 Env map[string]string 13 } 14 15 // NewKubectlOptions will return a pointer to new instance of KubectlOptions with the configured options 16 func NewKubectlOptions(contextName string, configPath string, namespace string) *KubectlOptions { 17 return &KubectlOptions{ 18 ContextName: contextName, 19 ConfigPath: configPath, 20 Namespace: namespace, 21 Env: map[string]string{}, 22 } 23 } 24 25 // GetConfigPath will return a sensible default if the config path is not set on the options. 26 func (kubectlOptions *KubectlOptions) GetConfigPath(t testing.TestingT) (string, error) { 27 // We predeclare `err` here so that we can update `kubeConfigPath` in the if block below. Otherwise, go complains 28 // saying `err` is undefined. 29 var err error 30 31 kubeConfigPath := kubectlOptions.ConfigPath 32 if kubeConfigPath == "" { 33 kubeConfigPath, err = GetKubeConfigPathE(t) 34 if err != nil { 35 return "", err 36 } 37 } 38 return kubeConfigPath, nil 39 }