Skip to content

Instantly share code, notes, and snippets.

@trstringer
Last active April 18, 2018 01:52
Show Gist options
  • Select an option

  • Save trstringer/4771e3ec2e392051a5d4648518653077 to your computer and use it in GitHub Desktop.

Select an option

Save trstringer/4771e3ec2e392051a5d4648518653077 to your computer and use it in GitHub Desktop.
// 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