diff --git a/xelon/kubernetes.go b/xelon/kubernetes.go index 7fa49a7..de91024 100644 --- a/xelon/kubernetes.go +++ b/xelon/kubernetes.go @@ -27,6 +27,19 @@ type KubernetesClusterHealth struct { LastCheckingData string `json:"lastCheckingData,omitempty"` } +type ClusterControlPlane struct { + CPUCoreCount int `json:"control_plane_cpu,omitempty"` + DiskSize int `json:"control_plane_disk,omitempty"` + Memory int `json:"control_plane_ram,omitempty"` + Nodes []ClusterControlPlaneNode `json:"nodes,omitempty"` +} + +type ClusterControlPlaneNode struct { + ID string `json:"identifier,omitempty"` + LocalVMID string `json:"localvmid,omitempty"` + Name string `json:"name,omitempty"` +} + type ClusterPool struct { CPUCoreCount int `json:"cpu,omitempty"` DiskSize int `json:"disk,omitempty"` @@ -46,11 +59,15 @@ func (v KubernetesCluster) String() string { return Stringify(v) } +func (v ClusterControlPlane) String() string { + return Stringify(v) +} + func (v ClusterPool) String() string { return Stringify(v) } -// List providers information about Kubernetes clusters. +// List provides information about Kubernetes clusters. func (s *KubernetesService) List(ctx context.Context) ([]KubernetesCluster, *Response, error) { path := fmt.Sprintf("%v/clusters", kubernetesBasePath) req, err := s.client.NewRequest(http.MethodGet, path, nil) @@ -67,7 +84,28 @@ func (s *KubernetesService) List(ctx context.Context) ([]KubernetesCluster, *Res return kubernetesClusters, resp, nil } -// ListClusterPools providers information about cluster pools on Kubernetes cluster. +// ListControlPlanes provides information about control plane on Kubernetes cluster. +func (s *KubernetesService) ListControlPlanes(ctx context.Context, kubernetesClusterID string) (*ClusterControlPlane, *Response, error) { + if kubernetesClusterID == "" { + return nil, nil, ErrEmptyArgument + } + + path := fmt.Sprintf("%v/%v/cluster-control-planes", kubernetesBasePath, kubernetesClusterID) + req, err := s.client.NewRequest(http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + clusterControlPlane := new(ClusterControlPlane) + resp, err := s.client.Do(ctx, req, clusterControlPlane) + if err != nil { + return nil, resp, err + } + + return clusterControlPlane, resp, nil +} + +// ListClusterPools provides information about cluster pools on Kubernetes cluster. func (s *KubernetesService) ListClusterPools(ctx context.Context, kubernetesClusterID string) ([]ClusterPool, *Response, error) { if kubernetesClusterID == "" { return nil, nil, ErrEmptyArgument diff --git a/xelon/kubernetes_test.go b/xelon/kubernetes_test.go index 879598b..b202829 100644 --- a/xelon/kubernetes_test.go +++ b/xelon/kubernetes_test.go @@ -28,6 +28,46 @@ func TestKubernetes_List(t *testing.T) { assert.Equal(t, expected, clusters) } +func TestKubernetes_ListControlPlanes(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/kubernetes-talos/abc/cluster-control-planes", func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method) + _, _ = fmt.Fprint(w, ` +{ + "control_plane_cpu": 2, + "control_plane_disk": 50, + "control_plane_ram": 4, + "nodes": [ + {"identifier":"def","localvmid":"def123","name":"cp-node-1"}, + {"identifier":"ghi","localvmid":"ghi456","name":"cp-node-2"} + ] +}`) + }) + expected := &ClusterControlPlane{ + CPUCoreCount: 2, + DiskSize: 50, + Memory: 4, + Nodes: []ClusterControlPlaneNode{ + {ID: "def", LocalVMID: "def123", Name: "cp-node-1"}, + {ID: "ghi", LocalVMID: "ghi456", Name: "cp-node-2"}, + }, + } + + controlPlanes, _, err := client.Kubernetes.ListControlPlanes(ctx, "abc") + + assert.NoError(t, err) + assert.Equal(t, expected, controlPlanes) +} + +func TestKubernetes_ListControlPlanes_emptyKubernetesClusterID(t *testing.T) { + _, _, err := client.Kubernetes.ListControlPlanes(ctx, "") + + assert.Error(t, err) + assert.Equal(t, ErrEmptyArgument, err) +} + func TestKubernetes_ListClusterPools(t *testing.T) { setup() defer teardown()