I am watching pods and get event from channel ResultChan(), now I want to parse event.Object. I saw a piece of code like this: event.Object.(*apiv1.Pod), please see the below code, but unfortunately k8s.io/client-go/pkg/api/v1 is retired, this piece of code doesn't work.
My question is, how to get Pod information from event.Object? What new API can access or parse event.Object?
import (
apiv1 "k8s.io/client-go/pkg/api/v1"
)
watcher, err := k8sClient.CoreV1().Pods(namespace).Watch(ctx, metav1.ListOptions{
LabelSelector: labels,
})
event := <-watcher.ResultChan():
pod, ok := event.Object.(*apiv1.Pod)
It seems that with version 5 there was indeed breaking API change:
So no instead of the
k8s.io/client-go/pkg/api/v1
you can usek8s.io/api/core/v1
: