forked from cr7258/kubernetes-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.informer.go
More file actions
36 lines (32 loc) · 806 Bytes
/
5.informer.go
File metadata and controls
36 lines (32 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"fmt"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"
"my-controller-runtime/lib"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"time"
)
/**
* @description 查看 Manager 中的 Informer
* @author chengzw
* @since 2023/7/29
* @link
*/
func main() {
mgr, err := manager.New(lib.K8sRestConfig(),
manager.Options{
Logger: logf.Log.WithName("test"),
Namespace: "default", // 只监控 default namespace 下的资源
})
lib.Check(err)
go func() {
time.Sleep(time.Second * 2)
podInformer, _ := mgr.GetCache().GetInformer(context.Background(), &v1.Pod{})
fmt.Println(podInformer.(cache.SharedIndexInformer).GetIndexer().ListKeys())
}()
err = mgr.Start(context.Background())
lib.Check(err)
}