nodes_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package nodestats
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "net/http"
  6. "testing"
  7. "github.com/opencost/opencost/core/pkg/clustercache"
  8. "github.com/opencost/opencost/core/pkg/kubeconfig"
  9. v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  10. "k8s.io/client-go/kubernetes"
  11. )
  12. func TestNodeSummaryStuff(t *testing.T) {
  13. t.Skip("Skipping live test for node summary client")
  14. client, err := kubeconfig.LoadKubeClient("")
  15. if err != nil {
  16. t.Fatalf("failed to load kube client: %v", err)
  17. }
  18. clusterConfig, err := kubeconfig.LoadKubeconfig("")
  19. if err != nil {
  20. t.Fatalf("failed to load kubeconfig: %v", err)
  21. }
  22. cache := NewTestClusterCache(client)
  23. transport := &http.Transport{
  24. TLSClientConfig: &tls.Config{
  25. InsecureSkipVerify: true,
  26. },
  27. }
  28. config := NewNodeClientConfig("cluster-one", 10, transport, "", "", NodeClientProxyConfig{
  29. ForceKubeProxy: true,
  30. LocalProxy: "http://localhost:8080",
  31. })
  32. statsClient := NewNodeStatsSummaryClient(cache, config, clusterConfig)
  33. summary, err := statsClient.GetNodeData()
  34. if err != nil {
  35. t.Fatalf("failed to get node data: %v", err)
  36. }
  37. for _, s := range summary {
  38. if s == nil {
  39. t.Error("received nil summary data")
  40. continue
  41. }
  42. t.Logf("Node Summary: %+v", s)
  43. }
  44. }
  45. type NodesOnlyClusterCache struct {
  46. k8sClient kubernetes.Interface
  47. }
  48. func NewTestClusterCache(k8sClient kubernetes.Interface) *NodesOnlyClusterCache {
  49. return &NodesOnlyClusterCache{
  50. k8sClient: k8sClient,
  51. }
  52. }
  53. // Run starts the watcher processes
  54. func (tcc *NodesOnlyClusterCache) Run() {}
  55. // Stops the watcher processes
  56. func (tcc *NodesOnlyClusterCache) Stop() {}
  57. // GetAllNamespaces returns all the cached namespaces
  58. func (tcc *NodesOnlyClusterCache) GetAllNamespaces() []*clustercache.Namespace { return nil }
  59. // GetAllNodes returns all the cached nodes
  60. func (tcc *NodesOnlyClusterCache) GetAllNodes() []*clustercache.Node {
  61. nodes, err := tcc.k8sClient.CoreV1().Nodes().List(context.Background(), v1.ListOptions{})
  62. if err != nil {
  63. return nil
  64. }
  65. var nodeList []*clustercache.Node
  66. for _, n := range nodes.Items {
  67. nodeList = append(nodeList, clustercache.TransformNode(&n))
  68. }
  69. return nodeList
  70. }
  71. // GetAllPods returns all the cached pods
  72. func (tcc *NodesOnlyClusterCache) GetAllPods() []*clustercache.Pod { return nil }
  73. // GetAllServices returns all the cached services
  74. func (tcc *NodesOnlyClusterCache) GetAllServices() []*clustercache.Service { return nil }
  75. // GetAllDaemonSets returns all the cached DaemonSets
  76. func (tcc *NodesOnlyClusterCache) GetAllDaemonSets() []*clustercache.DaemonSet { return nil }
  77. // GetAllDeployments returns all the cached deployments
  78. func (tcc *NodesOnlyClusterCache) GetAllDeployments() []*clustercache.Deployment { return nil }
  79. // GetAllStatfulSets returns all the cached StatefulSets
  80. func (tcc *NodesOnlyClusterCache) GetAllStatefulSets() []*clustercache.StatefulSet { return nil }
  81. // GetAllReplicaSets returns all the cached ReplicaSets
  82. func (tcc *NodesOnlyClusterCache) GetAllReplicaSets() []*clustercache.ReplicaSet { return nil }
  83. // GetAllPersistentVolumes returns all the cached persistent volumes
  84. func (tcc *NodesOnlyClusterCache) GetAllPersistentVolumes() []*clustercache.PersistentVolume {
  85. return nil
  86. }
  87. // GetAllPersistentVolumeClaims returns all the cached persistent volume claims
  88. func (tcc *NodesOnlyClusterCache) GetAllPersistentVolumeClaims() []*clustercache.PersistentVolumeClaim {
  89. return nil
  90. }
  91. // GetAllStorageClasses returns all the cached storage classes
  92. func (tcc *NodesOnlyClusterCache) GetAllStorageClasses() []*clustercache.StorageClass { return nil }
  93. // GetAllJobs returns all the cached jobs
  94. func (tcc *NodesOnlyClusterCache) GetAllJobs() []*clustercache.Job { return nil }
  95. // GetAllPodDisruptionBudgets returns all cached pod disruption budgets
  96. func (tcc *NodesOnlyClusterCache) GetAllPodDisruptionBudgets() []*clustercache.PodDisruptionBudget {
  97. return nil
  98. }
  99. // GetAllReplicationControllers returns all cached replication controllers
  100. func (tcc *NodesOnlyClusterCache) GetAllReplicationControllers() []*clustercache.ReplicationController {
  101. return nil
  102. }