Created
March 29, 2021 08:55
-
-
Save tamalsaha/e8caaa62755e30d31d549d689835068b 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 ( | |
"context" | |
"fmt" | |
"net/http" | |
"github.com/golang/glog" | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/runtime/schema" | |
"k8s.io/client-go/dynamic" | |
"k8s.io/client-go/kubernetes" | |
_ "k8s.io/client-go/plugin/pkg/client/auth" | |
"k8s.io/client-go/tools/clientcmd" | |
) | |
func main() { | |
masterURL := "" | |
// kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config") | |
kubeconfigPath := "/home/tamal/go/src/github.com/kompute/virtual-kubernetes/config" | |
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) | |
if err != nil { | |
glog.Fatalf("Could not get Kubernetes config: %s", err) | |
} | |
dc := dynamic.NewForConfigOrDie(config) | |
ns2, err := dc.Resource(schema.GroupVersionResource{ | |
Group: "", | |
Version: "v1", | |
Resource: "namespaces", | |
}).List(context.TODO(), metav1.ListOptions{}) | |
if err != nil { | |
panic(err) | |
} | |
for _, ns := range ns2.Items { | |
fmt.Println(ns.GetName()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment