Please open an issue on the client-go repo and link the blog post this came from.
On Mon, May 14, 2018 at 5:34 AM <holger.prot...@springer.com> wrote: > Hello, I tried to follow the example of the blog post for the Polymorphic > scale client, but it fails with: > > `panic: unable to get client for StatefulSet.apps: unable to get full > preferred group-version-resource for StatefulSet.apps: the cache has not > been filled yet` > > ``` > package main > > import ( > "flag" > "fmt" > "log" > "os" > "path/filepath" > > "k8s.io/client-go/kubernetes" > "k8s.io/client-go/tools/clientcmd" > _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" > "k8s.io/client-go/discovery" > "k8s.io/client-go/scale" > "k8s.io/client-go/dynamic" > "k8s.io/apimachinery/pkg/runtime/schema" > discocache "k8s.io/client-go/discovery/cached" > apimeta "k8s.io/apimachinery/pkg/api/meta" > "k8s.io/client-go/scale/scheme/appsv1beta1" > ) > > func main() { > var ns string > flag.StringVar(&ns, "namespace", "", "namespace") > > // Bootstrap k8s configuration from local Kubernetes config > file > kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config") > log.Println("Using kubeconfig file: ", kubeconfig) > config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) > if err != nil { > log.Fatal(err) > } > > // Create an rest client not targeting specific API version > clientset, err := kubernetes.NewForConfig(config) > if err != nil { > log.Fatal(err) > } > > cachedDiscovery := > discocache.NewMemCacheClient(clientset.Discovery()) > cachedDiscovery.Fresh() > restMapper := > discovery.NewDeferredDiscoveryRESTMapper(cachedDiscovery, > apimeta.InterfacesForUnstructured) > scaleKindResolver := > scale.NewDiscoveryScaleKindResolver(clientset.Discovery()) > scaleClient, err := scale.NewForConfig(config, restMapper, > dynamic.LegacyAPIPathResolverFunc, scaleKindResolver) > > scale, err := scaleClient.Scales("default").Get( > schema.GroupResource{Group: appsv1beta1.GroupName, > Resource: "StatefulSet"}, "worker") > if err != nil { > panic(err.Error()) > } > > fmt.Println(scale.Status) > } > ``` > > Not sure whats the problem here? It's because the empty cache, or is my > GroupResource wrong? > > -- > You received this message because you are subscribed to the Google Groups > "Kubernetes user discussion and Q&A" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to kubernetes-users+unsubscr...@googlegroups.com. > To post to this group, send email to kubernetes-users@googlegroups.com. > Visit this group at https://groups.google.com/group/kubernetes-users. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group. To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscr...@googlegroups.com. To post to this group, send email to kubernetes-users@googlegroups.com. Visit this group at https://groups.google.com/group/kubernetes-users. For more options, visit https://groups.google.com/d/optout.