Last active
April 18, 2018 01:52
-
-
Save trstringer/4771e3ec2e392051a5d4648518653077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment