Closed JCzz closed 5 months ago
Hi, I suspect that path to config file contains ":"
log message:
client.go:45: Configuring Kubernetes client using config file /Users/<name>/.kube/config: with context
contains ":", and it is not added from logs:
logger.Logf(t, "Configuring Kubernetes client using config file %s with context %s", kubeConfigPath, options.ContextName)
https://github.com/gruntwork-io/terratest/blob/master/modules/k8s/client.go#L45
Thanks @denis256 That was indeed the case. Way back I created this:
export KUBECONFIG=~/.kube/config:$(find ~/.kube/custom -type f | tr '\n' ':')
Trying to make it easier to add new config files.
Describe the bug I am trying to run example code.
To Reproduce Just run: kubernetes_basic_example_test.go
Expected behavior I was hoping for the example to work.
Nice to have
package main
import ( "context" "fmt" "os" "path/filepath"
)
func main() { userHomeDir, err := os.UserHomeDir() if err != nil { fmt.Printf("error getting user home dir: %v\n", err) os.Exit(1) } kubeConfigPath := filepath.Join(userHomeDir, ".kube", "config") fmt.Printf("Using kubeconfig: %s\n", kubeConfigPath)
}
func ListPods(namespace string, client kubernetes.Interface) (*v1.PodList, error) { fmt.Println("Get Kubernetes Pods") pods, err := client.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{}) if err != nil { err = fmt.Errorf("error getting pods: %v\n", err) return nil, err } return pods, nil }
func ListNamespaces(client kubernetes.Interface) (*v1.NamespaceList, error) { fmt.Println("Get Kubernetes Namespaces") namespaces, err := client.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) if err != nil { err = fmt.Errorf("error getting namespaces: %v\n", err) return nil, err } return namespaces, nil }