kacejot

kubernetes dynamic client

May 7th, 2019
309
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.  
  6.     v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  7.     "k8s.io/apimachinery/pkg/runtime/schema"
  8.     "k8s.io/client-go/dynamic"
  9.     "k8s.io/client-go/tools/clientcmd"
  10. )
  11.  
  12. func main() {
  13.     config, _ := clientcmd.BuildConfigFromFlags("", "/home/maxim/.kube/config")
  14.     client := dynamic.NewForConfigOrDie(config)
  15.  
  16.     result, err := client.
  17.         Resource(schema.GroupVersionResource{
  18.             Group:    "apps",
  19.             Version:  "v1beta2",
  20.             Resource: "deployments",
  21.         }).
  22.         Namespace("kube-system").
  23.         List(v1.ListOptions{})
  24.  
  25.     fmt.Printf("%v\n%v\n", err, len(result.Items))
  26. }
RAW Paste Data