Guest User

Untitled

a guest
Apr 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // retrieve the Kubernetes cluster client from outside of the cluster
  2. func getKubernetesClient() (kubernetes.Interface, myresourceclientset.Interface) {
  3. // construct the path to resolve to `~/.kube/config`
  4. kubeConfigPath := os.Getenv("HOME") + "/.kube/config"
  5.  
  6. // create the config from the path
  7. config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
  8. if err != nil {
  9. log.Fatalf("getClusterConfig: %v", err)
  10. }
  11.  
  12. // generate the client based off of the config
  13. client, err := kubernetes.NewForConfig(config)
  14. if err != nil {
  15. log.Fatalf("getClusterConfig: %v", err)
  16. }
  17.  
  18. myresourceClient, err := myresourceclientset.NewForConfig(config)
  19. if err != nil {
  20. log.Fatalf("getClusterConfig: %v", err)
  21. }
  22.  
  23. log.Info("Successfully constructed k8s client")
  24. return client, myresourceClient
  25. }
Add Comment
Please, Sign In to add comment