Pod使用集群kubeconfig
import "k8s.io/client-go/rest"
cfg, err := rest.InClusterConfig()
if err != nil {
klog.Fatalf("Error building kubeconfig: %s", err.Error())
}
list/watch指定namespace
informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithNamespace("default"))
list/watch指定fieldSelector
informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTweakListOptions(
func(options *metav1.ListOptions) {
options.FieldSelector = "metadata.name=test"
}))
list/watch指定labelSelector
informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTweakListOptions(
func(options *metav1.ListOptions) {
options.LabelSelector = "app=test"
}))
标签:技巧,informerFactory,NewSharedInformerFactoryWithOptions,informers,kubeClient,clie From: https://www.cnblogs.com/WJQ2017/p/18069768