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!
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!
Most helpful comment
Can you try
clientset.Extensions().RESTClient()at the second line?