transfer.go 930 B

123456789101112131415161718192021222324252627282930
  1. package transfer
  2. import (
  3. "context"
  4. "k8s.io/client-go/informers"
  5. "k8s.io/client-go/kubernetes"
  6. "time"
  7. )
  8. type CwK8sClient struct {
  9. K8sClient *kubernetes.Clientset
  10. InformerSharedfactory informers.SharedInformerFactory
  11. ctx context.Context
  12. }
  13. func NewCwK8sClient(ctx context.Context, client *kubernetes.Clientset) *CwK8sClient {
  14. sharedInformer := informers.NewSharedInformerFactory(client, 30*time.Second)
  15. sharedInformer.Core().V1().Pods().Informer()
  16. sharedInformer.Core().V1().Nodes().Informer()
  17. sharedInformer.Core().V1().Namespaces().Informer()
  18. sharedInformer.Apps().V1().StatefulSets().Informer()
  19. sharedInformer.Apps().V1().DaemonSets().Informer()
  20. sharedInformer.Apps().V1().Deployments().Informer()
  21. sharedInformer.Apps().V1().ReplicaSets().Informer()
  22. return &CwK8sClient{
  23. K8sClient: client,
  24. ctx: ctx,
  25. InformerSharedfactory: sharedInformer,
  26. }
  27. }