clustercache2.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. policyv1 "k8s.io/api/policy/v1"
  8. stv1 "k8s.io/api/storage/v1"
  9. "k8s.io/client-go/kubernetes"
  10. )
  11. type KubernetesClusterCacheV2 struct {
  12. namespaceStore *GenericStore[*v1.Namespace, *Namespace]
  13. nodeStore *GenericStore[*v1.Node, *Node]
  14. podStore *GenericStore[*v1.Pod, *Pod]
  15. serviceStore *GenericStore[*v1.Service, *Service]
  16. daemonSetStore *GenericStore[*appsv1.DaemonSet, *DaemonSet]
  17. deploymentStore *GenericStore[*appsv1.Deployment, *Deployment]
  18. statefulSetStore *GenericStore[*appsv1.StatefulSet, *StatefulSet]
  19. persistentVolumeStore *GenericStore[*v1.PersistentVolume, *PersistentVolume]
  20. persistentVolumeClaimStore *GenericStore[*v1.PersistentVolumeClaim, *PersistentVolumeClaim]
  21. storageClassStore *GenericStore[*stv1.StorageClass, *StorageClass]
  22. jobStore *GenericStore[*batchv1.Job, *Job]
  23. replicationControllerStore *GenericStore[*v1.ReplicationController, *ReplicationController]
  24. replicaSetStore *GenericStore[*appsv1.ReplicaSet, *ReplicaSet]
  25. pdbStore *GenericStore[*policyv1.PodDisruptionBudget, *PodDisruptionBudget]
  26. }
  27. func NewKubernetesClusterCacheV2(clientset kubernetes.Interface) *KubernetesClusterCacheV2 {
  28. ctx := context.TODO()
  29. return &KubernetesClusterCacheV2{
  30. namespaceStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "namespaces", transformNamespace),
  31. nodeStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "nodes", transformNode),
  32. persistentVolumeClaimStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "persistentvolumeclaims", transformPersistentVolumeClaim),
  33. persistentVolumeStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "persistentvolumes", transformPersistentVolume),
  34. podStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "pods", transformPod),
  35. replicationControllerStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "replicationcontrollers", transformReplicationController),
  36. serviceStore: CreateStoreAndWatch(ctx, clientset.CoreV1().RESTClient(), "services", transformService),
  37. daemonSetStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "daemonsets", transformDaemonSet),
  38. deploymentStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "deployments", transformDeployment),
  39. replicaSetStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "replicasets", transformReplicaSet),
  40. statefulSetStore: CreateStoreAndWatch(ctx, clientset.AppsV1().RESTClient(), "statefulsets", transformStatefulSet),
  41. storageClassStore: CreateStoreAndWatch(ctx, clientset.StorageV1().RESTClient(), "storageclasses", transformStorageClass),
  42. jobStore: CreateStoreAndWatch(ctx, clientset.BatchV1().RESTClient(), "jobs", transformJob),
  43. pdbStore: CreateStoreAndWatch(ctx, clientset.PolicyV1().RESTClient(), "poddisruptionbudgets", transformPodDisruptionBudget),
  44. }
  45. }
  46. func (kcc *KubernetesClusterCacheV2) Run() {
  47. }
  48. func (kcc *KubernetesClusterCacheV2) Stop() {
  49. }
  50. func (kcc *KubernetesClusterCacheV2) GetAllNamespaces() []*Namespace {
  51. return kcc.namespaceStore.GetAll()
  52. }
  53. func (kcc *KubernetesClusterCacheV2) GetAllNodes() []*Node {
  54. return kcc.nodeStore.GetAll()
  55. }
  56. func (kcc *KubernetesClusterCacheV2) GetAllPods() []*Pod {
  57. return kcc.podStore.GetAll()
  58. }
  59. func (kcc *KubernetesClusterCacheV2) GetAllServices() []*Service {
  60. return kcc.serviceStore.GetAll()
  61. }
  62. func (kcc *KubernetesClusterCacheV2) GetAllDaemonSets() []*DaemonSet {
  63. return kcc.daemonSetStore.GetAll()
  64. }
  65. func (kcc *KubernetesClusterCacheV2) GetAllDeployments() []*Deployment {
  66. return kcc.deploymentStore.GetAll()
  67. }
  68. func (kcc *KubernetesClusterCacheV2) GetAllStatefulSets() []*StatefulSet {
  69. return kcc.statefulSetStore.GetAll()
  70. }
  71. func (kcc *KubernetesClusterCacheV2) GetAllPersistentVolumes() []*PersistentVolume {
  72. return kcc.persistentVolumeStore.GetAll()
  73. }
  74. func (kcc *KubernetesClusterCacheV2) GetAllPersistentVolumeClaims() []*PersistentVolumeClaim {
  75. return kcc.persistentVolumeClaimStore.GetAll()
  76. }
  77. func (kcc *KubernetesClusterCacheV2) GetAllStorageClasses() []*StorageClass {
  78. return kcc.storageClassStore.GetAll()
  79. }
  80. func (kcc *KubernetesClusterCacheV2) GetAllJobs() []*Job {
  81. return kcc.jobStore.GetAll()
  82. }
  83. func (kcc *KubernetesClusterCacheV2) GetAllReplicationControllers() []*ReplicationController {
  84. return kcc.replicationControllerStore.GetAll()
  85. }
  86. func (kcc *KubernetesClusterCacheV2) GetAllReplicaSets() []*ReplicaSet {
  87. return kcc.replicaSetStore.GetAll()
  88. }
  89. func (kcc *KubernetesClusterCacheV2) GetAllPodDisruptionBudgets() []*PodDisruptionBudget {
  90. return kcc.pdbStore.GetAll()
  91. }