2
0

clustercache2.go 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package clustercache
  2. import (
  3. "context"
  4. appsv1 "k8s.io/api/apps/v1"
  5. batchv1 "k8s.io/api/batch/v1"
  6. v1 "k8s.io/api/core/v1"
  7. stv1 "k8s.io/api/storage/v1"
  8. "k8s.io/client-go/kubernetes"
  9. )
  10. type KubernetesClusterCacheV2 struct {
  11. namespaceStore *GenericStore[*v1.Namespace, *Namespace]
  12. nodeStore *GenericStore[*v1.Node, *Node]
  13. podStore *GenericStore[*v1.Pod, *Pod]
  14. serviceStore *GenericStore[*v1.Service, *Service]
  15. daemonSetStore *GenericStore[*appsv1.DaemonSet, *DaemonSet]
  16. deploymentStore *GenericStore[*appsv1.Deployment, *Deployment]
  17. statefulSetStore *GenericStore[*appsv1.StatefulSet, *StatefulSet]
  18. persistentVolumeStore *GenericStore[*v1.PersistentVolume, *PersistentVolume]
  19. persistentVolumeClaimStore *GenericStore[*v1.PersistentVolumeClaim, *PersistentVolumeClaim]
  20. storageClassStore *GenericStore[*stv1.StorageClass, *StorageClass]
  21. jobStore *GenericStore[*batchv1.Job, *Job]
  22. }
  23. func NewKubernetesClusterCache2(clientset kubernetes.Interface) *KubernetesClusterCacheV2 {
  24. ctx := context.TODO()
  25. return &KubernetesClusterCacheV2{
  26. namespaceStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "namespaces", transformNamespace),
  27. nodeStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "nodes", transformNode),
  28. podStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "pods", transformPod),
  29. serviceStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "services", transformService),
  30. daemonSetStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "daemonsets", transformDaemonSet),
  31. deploymentStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "deployments", transformDeployment),
  32. statefulSetStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "statefulsets", transformStatefulSet),
  33. persistentVolumeStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "persistentvolumes", transformPersistentVolume),
  34. persistentVolumeClaimStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "persistentvolumeclaims", transformPersistentVolumeClaim),
  35. storageClassStore: CreateStoreAndWatch(ctx, clientset.StorageV1().RESTClient(), "storageclasses", transformStorageClass),
  36. jobStore: CreateStoreAndWatch(ctx, clientset.BatchV1().RESTClient(), "jobs", transformJob),
  37. }
  38. }
  39. func (kcc *KubernetesClusterCacheV2) Run() {
  40. }
  41. func (kcc *KubernetesClusterCacheV2) Stop() {
  42. }
  43. func (kcc *KubernetesClusterCacheV2) SetConfigMapUpdateFunc(f func(interface{})) {}
  44. func (kcc *KubernetesClusterCacheV2) GetAllNamespaces() []*Namespace {
  45. return kcc.namespaceStore.GetAll()
  46. }
  47. func (kcc *KubernetesClusterCacheV2) GetAllNodes() []*Node {
  48. return kcc.nodeStore.GetAll()
  49. }
  50. func (kcc *KubernetesClusterCacheV2) GetAllPods() []*Pod {
  51. return kcc.podStore.GetAll()
  52. }
  53. func (kcc *KubernetesClusterCacheV2) GetAllServices() []*Service {
  54. return kcc.serviceStore.GetAll()
  55. }
  56. func (kcc *KubernetesClusterCacheV2) GetAllDaemonSets() []*DaemonSet {
  57. return kcc.daemonSetStore.GetAll()
  58. }
  59. func (kcc *KubernetesClusterCacheV2) GetAllDeployments() []*Deployment {
  60. return kcc.deploymentStore.GetAll()
  61. }
  62. func (kcc *KubernetesClusterCacheV2) GetAllStatefulSets() []*StatefulSet {
  63. return kcc.statefulSetStore.GetAll()
  64. }
  65. func (kcc *KubernetesClusterCacheV2) GetAllPersistentVolumes() []*PersistentVolume {
  66. return kcc.persistentVolumeStore.GetAll()
  67. }
  68. func (kcc *KubernetesClusterCacheV2) GetAllPersistentVolumeClaims() []*PersistentVolumeClaim {
  69. return kcc.persistentVolumeClaimStore.GetAll()
  70. }
  71. func (kcc *KubernetesClusterCacheV2) GetAllStorageClasses() []*StorageClass {
  72. return kcc.storageClassStore.GetAll()
  73. }
  74. func (kcc *KubernetesClusterCacheV2) GetAllJobs() []*Job {
  75. return kcc.jobStore.GetAll()
  76. }