Client-go: [Question] How to watch for deployments?

Created on 28 Feb 2017  路  3Comments  路  Source: kubernetes/client-go

I am a newbie in both Go and Kubernetes. When I run the code below...

import "k8s.io/client-go/pkg/apis/extensions/v1beta1"

...

    watchlist := cache.NewListWatchFromClient(
        clientset.Core().RESTClient(),
        "deployments", v1.NamespaceAll,
        fields.Everything())

    _, controller := cache.NewInformer(
        watchlist,
        &v1beta1.Deployment{},
        time.Second*0,
        cache.ResourceEventHandlerFuncs{
            AddFunc: func(obj interface{}) {
                jsn, _ := json.Marshal(obj)
                fmt.Printf("Deployment added: %s\n", jsn)
            },
            DeleteFunc: func(obj interface{}) {
                jsn, _ := json.Marshal(obj)
                fmt.Printf("Deployment deleted: %s\n", jsn)
            },
            UpdateFunc: func(oldObj, newObj interface{}) {
                fmt.Printf("Deployment changed\n")
            },
        },
    )

...I get the following error:

E0228 11:19:08.654259    4931 reflector.go:199] github.com/softonic/kubewatch/vendor/k8s.io/client-go/tools/cache/reflector.go:94: Failed to list <nil>: the server could not find the requested resource

What am I doing wrong? Thank you!

Most helpful comment

Can you try clientset.Extensions().RESTClient() at the second line?

All 3 comments

Can you try clientset.Extensions().RESTClient() at the second line?

@caesarxuchao you're my hero of the day!

@caesarxuchao wonderful that was it. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterwillcn picture peterwillcn  路  5Comments

vklonghml picture vklonghml  路  4Comments

CSharpRU picture CSharpRU  路  7Comments

strugglingyouth picture strugglingyouth  路  5Comments

alexec picture alexec  路  5Comments