package main import ( "context" "fmt" "log" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" ) type WatchEvent struct { Type string `json:"type" protobuf:"bytes,1,opt,name=type"` // Object is: // * If Type is Added or Modified: the new state of the object. // * If Type is Deleted: the state of the object immediately before deletion. // * If Type is Error: *Status is recommended; other types may make sense // depending on context. Object runtime.RawExtension `json:"object" protobuf:"bytes,2,opt,name=object"` } func watchEvents(clientset *kubernetes.Clientset, namespace string) chan WatchEvent { for { watch, err := clientset.BatchV1().Jobs(namespace).Watch(context.TODO(), metav1.ListOptions{}) if err != nil { log.Fatal(err) } watch.ResultChan() fmt.Println("ResultChan closed, restarting watch") } }