Skip to content

Instantly share code, notes, and snippets.

@feloy
Last active June 17, 2018 14:09
Show Gist options
  • Save feloy/4eb39899dc966ae8e0023590d7aa484b to your computer and use it in GitHub Desktop.
Save feloy/4eb39899dc966ae8e0023590d7aa484b to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
type k8s struct {
clientset kubernetes.Interface
}
func newK8s() (*k8s, error) {
path := os.Getenv("HOME") + "/.kube/config"
config, err := clientcmd.BuildConfigFromFlags("", path)
if err != nil {
return nil, err
}
client := k8s{}
client.clientset, err = kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
return &client, nil
}
func main() {
k8s, err := newK8s()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(k8s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment