Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // retrieve the Kubernetes cluster client from outside of the cluster
- func getKubernetesClient() (kubernetes.Interface, myresourceclientset.Interface) {
- // construct the path to resolve to `~/.kube/config`
- kubeConfigPath := os.Getenv("HOME") + "/.kube/config"
- // create the config from the path
- config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
- if err != nil {
- log.Fatalf("getClusterConfig: %v", err)
- }
- // generate the client based off of the config
- client, err := kubernetes.NewForConfig(config)
- if err != nil {
- log.Fatalf("getClusterConfig: %v", err)
- }
- myresourceClient, err := myresourceclientset.NewForConfig(config)
- if err != nil {
- log.Fatalf("getClusterConfig: %v", err)
- }
- log.Info("Successfully constructed k8s client")
- return client, myresourceClient
- }
Add Comment
Please, Sign In to add comment