Last active
June 17, 2018 14:09
-
-
Save feloy/4eb39899dc966ae8e0023590d7aa484b 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
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