Created
October 18, 2022 17:06
-
-
Save nickzelei/991b4bbf87f9c7e5d66181f94cb36caf to your computer and use it in GitHub Desktop.
Kube Connect
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 ( | |
| "os" | |
| "k8s.io/client-go/kubernetes" | |
| "k8s.io/client-go/tools/clientcmd" | |
| clientcmdapi "k8s.io/client-go/tools/clientcmd/api" | |
| ) | |
| func main() { | |
| configPath := "/Users/nick/.kube/config" | |
| cfg, err := clientcmd.BuildConfigFromKubeconfigGetter("", kubeConfigGetterFn(configPath)) | |
| if err != nil { | |
| panic(err) | |
| } | |
| kubeclient, err := kubernetes.NewForConfig(cfg) | |
| if err != nil { | |
| panic(err) | |
| } | |
| } | |
| func kubeConfigGetterFn(configPath string) clientcmd.KubeconfigGetter { | |
| return func() (*clientcmdapi.Config, error) { | |
| bites, err := os.ReadFile(configPath) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return clientcmd.Load(bites) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment