k8s.io/client-go/pkg/api/v1退役了,如何解析event.Object?

k8s.io/client-go/pkg/api/v1 was retired, how to parse event.Object?

我正在观看 pods 并从通道 ResultChan() 获取事件,现在我想解析 event.Object。看到一段代码是这样的:event.Object.(*apiv1.Pod),请看下面的代码,可惜k8s.io/client-go/pkg/api/v1退休了,这段代码不行.

我的问题是,如何从event.Object获取Pod信息?哪些新 API 可以访问或解析 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)

似乎版本 5 确实有突破性的 API 变化:

Moved pkg/api and pkg/apis to k8s.io/api. Other kubernetes repositories also import types from there, so they are composable with client-go.

所以不用 k8s.io/client-go/pkg/api/v1 你可以使用 k8s.io/api/core/v1 :

import ( 
    corev1  "http://k8s.io/api/core/v1"  
    "k8s.io/apimachinery/pkg/api/errors"
    metav1  "k8s.io/apimachinery/pkg/apis/meta/v1"
    "k8s.io/client-go/kubernetes"  
    "k8s.io/client-go/tools/clientcmd"
)