diff --git a/karbon/karbon_cluster_registration_service.go b/karbon/karbon_cluster_registration_service.go index 082db519..3778cd9f 100644 --- a/karbon/karbon_cluster_registration_service.go +++ b/karbon/karbon_cluster_registration_service.go @@ -2,6 +2,7 @@ package karbon import ( "context" + "fmt" "net/http" "github.com/google/uuid" @@ -66,47 +67,8 @@ func (op ClusterRegistrationOperations) GetK8sRegistration(ctx context.Context, } // GetK8sRegistrationList gets the k8s registration list -func (op ClusterRegistrationOperations) GetK8sRegistrationList(ctx context.Context) (*K8sClusterRegistrationListResponse, error) { - path := "/v1-alpha.1/k8s/cluster-registrations/" - req, err := op.httpClient.NewRequest(http.MethodGet, path, nil) - if err != nil { - return nil, err - } - karbonClusterActionResponse := new(K8sClusterRegistrationListResponse) - if err := op.httpClient.Do(ctx, req, karbonClusterActionResponse); err != nil { - return nil, err - } - return karbonClusterActionResponse, nil -} - -func (op ClusterRegistrationOperations) GetK8sRegistrationListPage1(ctx context.Context) (*K8sClusterRegistrationListResponse, error) { - path := "/v1-alpha.1/k8s/cluster-registrations?offset=0&page_size=1" - req, err := op.httpClient.NewRequest(http.MethodGet, path, nil) - if err != nil { - return nil, err - } - karbonClusterActionResponse := new(K8sClusterRegistrationListResponse) - if err := op.httpClient.Do(ctx, req, karbonClusterActionResponse); err != nil { - return nil, err - } - return karbonClusterActionResponse, nil -} - -func (op ClusterRegistrationOperations) GetK8sRegistrationListPage2(ctx context.Context) (*K8sClusterRegistrationListResponse, error) { - path := "/v1-alpha.1/k8s/cluster-registrations?offset=1&page_size=1" - req, err := op.httpClient.NewRequest(http.MethodGet, path, nil) - if err != nil { - return nil, err - } - karbonClusterActionResponse := new(K8sClusterRegistrationListResponse) - if err := op.httpClient.Do(ctx, req, karbonClusterActionResponse); err != nil { - return nil, err - } - return karbonClusterActionResponse, nil -} - -func (op ClusterRegistrationOperations) GetK8sRegistrationListEmpty(ctx context.Context) (*K8sClusterRegistrationListResponse, error) { - path := "/v1-alpha.1/k8s/cluster-registrations?offset=100&page_size=20" +func (op ClusterRegistrationOperations) GetK8sRegistrationList(ctx context.Context, offset, page_size int) (*K8sClusterRegistrationListResponse, error) { + path := fmt.Sprintf("/v1-alpha.1/k8s/cluster-registrations?offset=%d&page_size=%d", offset, page_size) req, err := op.httpClient.NewRequest(http.MethodGet, path, nil) if err != nil { return nil, err diff --git a/karbon/karbon_cluster_registration_service_test.go b/karbon/karbon_cluster_registration_service_test.go index b0b5b973..8bf737ad 100644 --- a/karbon/karbon_cluster_registration_service_test.go +++ b/karbon/karbon_cluster_registration_service_test.go @@ -521,7 +521,7 @@ func TestKarbonGetK8sRegistrationList(t *testing.T) { Name: t.Name(), }) // returns type K8sCreateClusterRegistrationResponse - response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationList(kctx) + response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationList(kctx, 0, 1) assert.NoError(t, err) validateK8sClusterRegistrationList(t, response) } @@ -537,7 +537,7 @@ func TestKarbonGetK8sRegistrationListEmpty(t *testing.T) { Name: t.Name(), }) // returns type K8sCreateClusterRegistrationResponse - response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationListEmpty(kctx) + response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationList(kctx, 100, 20) assert.NoError(t, err) expected := K8sClusterRegistrationListResponse{ Data: []*K8sClusterRegistration{}, @@ -559,7 +559,7 @@ func TestKarbonGetK8sRegistrationListPage1(t *testing.T) { Name: t.Name(), }) // returns type K8sCreateClusterRegistrationResponse - response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationListPage1(kctx) + response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationList(kctx, 0, 1) assert.NoError(t, err) expectedLen := 1 expectedTotal := int64(1) @@ -579,7 +579,7 @@ func TestKarbonGetK8sRegistrationListPage2(t *testing.T) { Name: t.Name(), }) // returns type K8sCreateClusterRegistrationResponse - response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationListPage2(kctx) + response, err := nkeClient.ClusterRegistrationOperations.GetK8sRegistrationList(kctx, 1, 1) assert.NoError(t, err) expectedLen := 0 expectedTotal := int64(1) diff --git a/karbon/mocks/TestKarbonGetK8sRegistrationList.yaml b/karbon/mocks/TestKarbonGetK8sRegistrationList.yaml index 3514b6fe..5b3bb321 100644 --- a/karbon/mocks/TestKarbonGetK8sRegistrationList.yaml +++ b/karbon/mocks/TestKarbonGetK8sRegistrationList.yaml @@ -8,7 +8,7 @@ spec: Proto: HTTP/1.1 ProtoMajor: "1" ProtoMinor: "1" - URL: https://10.44.193.89:9440/karbon/v1-alpha.1/k8s/cluster-registrations/ + URL: https://10.44.193.89:9440/karbon/v1-alpha.1/k8s/cluster-registrations?offset=0&page_size=1 name: http-client operation: GET type: HTTP_CLIENT @@ -16,7 +16,7 @@ spec: method: GET proto_major: 1 proto_minor: 1 - url: https://10.44.193.89:9440/karbon/v1-alpha.1/k8s/cluster-registrations/ + url: https://10.44.193.89:9440/karbon/v1-alpha.1/k8s/cluster-registrations?offset=0&page_size=1 header: Accept: application/json Content-Type: application/json @@ -28,13 +28,13 @@ spec: header: Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' Content-Type: application/json - Date: Mon, 20 Nov 2023 23:30:30 GMT + Date: Tue, 21 Nov 2023 12:43:49 GMT Server: envoy Strict-Transport-Security: max-age=8640000:includeSubdomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Dns-Prefetch-Control: "off" - X-Envoy-Upstream-Service-Time: "2393" + X-Envoy-Upstream-Service-Time: "582" X-Frame-Options: SAMEORIGIN X-Ntnx-Env: pc X-Ntnx-Product: pc.2023.4 @@ -42,7 +42,7 @@ spec: X-Powered-By: Express X-Xss-Protection: 1; mode=block body: | - {"data":[{"addons_info":{"NDK":{"addon_chart_name":"nutanix-juno","addon_description":"Juno is the service responsible for providing the AOS storage and data management features to workload running on Kubernetes.","addon_release_name":"juno","addon_release_status":"deployed","addon_version":"0.1.0"}},"categories_mapping":{"KubernetesClusterName":"nutest-capx-10191136"},"cluster_info":{"cluster_hb_timestamp":"2023-11-20 23:23:24.480776839 +0000 UTC","cpu_count":"16","k8s_version":"v1.23.10","memory_bytes":"34359738368","os_image":"Ubuntu 20.04.5 LTS","projects":"[{\"name\":\"onboarding-test1\",\"uuid\":\"986f9e44-1716-4cac-b411-6693cea10185\"}]","storage_capacity_bytes":"0","storage_used_bytes":"0","vg_count":"0","vm_count":"4"},"k8s_distribution":"CNCF Kubernetes","name":"nutest-capx-10191136","status":"kActive","uuid":"ffe36421-9d4d-4332-b416-34d0df74a172"}],"offset":0,"page_size":10,"total":1} + {"data":[{"addons_info":{"NDK":{"addon_chart_name":"nutanix-juno","addon_description":"Juno is the service responsible for providing the AOS storage and data management features to workload running on Kubernetes.","addon_release_name":"juno","addon_release_status":"deployed","addon_version":"0.1.0"}},"categories_mapping":{"KubernetesClusterName":"nutest-capx-10191136"},"cluster_info":{"cluster_hb_timestamp":"2023-11-21 12:35:55.883251419 +0000 UTC","cpu_count":"16","k8s_version":"v1.23.10","memory_bytes":"34359738368","os_image":"Ubuntu 20.04.5 LTS","projects":"[{\"name\":\"onboarding-test1\",\"uuid\":\"986f9e44-1716-4cac-b411-6693cea10185\"}]","storage_capacity_bytes":"0","storage_used_bytes":"0","vg_count":"0","vm_count":"4"},"k8s_distribution":"CNCF Kubernetes","name":"nutest-capx-10191136","status":"kActive","uuid":"ffe36421-9d4d-4332-b416-34d0df74a172"}],"offset":0,"page_size":1,"total":1} body_type: utf-8 status_message: "" proto_major: 0 diff --git a/karbon/mocks/TestKarbonGetK8sRegistrationListEmpty.yaml b/karbon/mocks/TestKarbonGetK8sRegistrationListEmpty.yaml index 5adf6018..ebe17e20 100644 --- a/karbon/mocks/TestKarbonGetK8sRegistrationListEmpty.yaml +++ b/karbon/mocks/TestKarbonGetK8sRegistrationListEmpty.yaml @@ -28,13 +28,13 @@ spec: header: Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' Content-Type: application/json - Date: Mon, 20 Nov 2023 23:30:31 GMT + Date: Tue, 21 Nov 2023 12:43:50 GMT Server: envoy Strict-Transport-Security: max-age=8640000:includeSubdomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Dns-Prefetch-Control: "off" - X-Envoy-Upstream-Service-Time: "492" + X-Envoy-Upstream-Service-Time: "266" X-Frame-Options: SAMEORIGIN X-Ntnx-Env: pc X-Ntnx-Product: pc.2023.4 diff --git a/karbon/mocks/TestKarbonGetK8sRegistrationListPage1.yaml b/karbon/mocks/TestKarbonGetK8sRegistrationListPage1.yaml index 3c045920..34305f7d 100644 --- a/karbon/mocks/TestKarbonGetK8sRegistrationListPage1.yaml +++ b/karbon/mocks/TestKarbonGetK8sRegistrationListPage1.yaml @@ -28,13 +28,13 @@ spec: header: Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' Content-Type: application/json - Date: Mon, 20 Nov 2023 23:30:33 GMT + Date: Tue, 21 Nov 2023 12:43:51 GMT Server: envoy Strict-Transport-Security: max-age=8640000:includeSubdomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Dns-Prefetch-Control: "off" - X-Envoy-Upstream-Service-Time: "1058" + X-Envoy-Upstream-Service-Time: "658" X-Frame-Options: SAMEORIGIN X-Ntnx-Env: pc X-Ntnx-Product: pc.2023.4 @@ -42,7 +42,7 @@ spec: X-Powered-By: Express X-Xss-Protection: 1; mode=block body: | - {"data":[{"addons_info":{"NDK":{"addon_chart_name":"nutanix-juno","addon_description":"Juno is the service responsible for providing the AOS storage and data management features to workload running on Kubernetes.","addon_release_name":"juno","addon_release_status":"deployed","addon_version":"0.1.0"}},"categories_mapping":{"KubernetesClusterName":"nutest-capx-10191136"},"cluster_info":{"cluster_hb_timestamp":"2023-11-20 23:23:24.480776839 +0000 UTC","cpu_count":"16","k8s_version":"v1.23.10","memory_bytes":"34359738368","os_image":"Ubuntu 20.04.5 LTS","projects":"[{\"name\":\"onboarding-test1\",\"uuid\":\"986f9e44-1716-4cac-b411-6693cea10185\"}]","storage_capacity_bytes":"0","storage_used_bytes":"0","vg_count":"0","vm_count":"4"},"k8s_distribution":"CNCF Kubernetes","name":"nutest-capx-10191136","status":"kActive","uuid":"ffe36421-9d4d-4332-b416-34d0df74a172"}],"offset":0,"page_size":1,"total":1} + {"data":[{"addons_info":{"NDK":{"addon_chart_name":"nutanix-juno","addon_description":"Juno is the service responsible for providing the AOS storage and data management features to workload running on Kubernetes.","addon_release_name":"juno","addon_release_status":"deployed","addon_version":"0.1.0"}},"categories_mapping":{"KubernetesClusterName":"nutest-capx-10191136"},"cluster_info":{"cluster_hb_timestamp":"2023-11-21 12:35:55.883251419 +0000 UTC","cpu_count":"16","k8s_version":"v1.23.10","memory_bytes":"34359738368","os_image":"Ubuntu 20.04.5 LTS","projects":"[{\"name\":\"onboarding-test1\",\"uuid\":\"986f9e44-1716-4cac-b411-6693cea10185\"}]","storage_capacity_bytes":"0","storage_used_bytes":"0","vg_count":"0","vm_count":"4"},"k8s_distribution":"CNCF Kubernetes","name":"nutest-capx-10191136","status":"kActive","uuid":"ffe36421-9d4d-4332-b416-34d0df74a172"}],"offset":0,"page_size":1,"total":1} body_type: utf-8 status_message: "" proto_major: 0 diff --git a/karbon/mocks/TestKarbonGetK8sRegistrationListPage2.yaml b/karbon/mocks/TestKarbonGetK8sRegistrationListPage2.yaml index b56cee1a..a1cdbae9 100644 --- a/karbon/mocks/TestKarbonGetK8sRegistrationListPage2.yaml +++ b/karbon/mocks/TestKarbonGetK8sRegistrationListPage2.yaml @@ -28,13 +28,13 @@ spec: header: Content-Security-Policy: 'default-src ''self'' https://*.nutanix.com; script-src ''self'' ''unsafe-inline'' ''unsafe-eval''; style-src ''self'' ''unsafe-inline''; connect-src ''self'' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src ''self'' blob: data:; frame-src ''self'' https://*.nutanix.com blob: data:' Content-Type: application/json - Date: Mon, 20 Nov 2023 23:30:34 GMT + Date: Tue, 21 Nov 2023 12:43:51 GMT Server: envoy Strict-Transport-Security: max-age=8640000:includeSubdomains Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Dns-Prefetch-Control: "off" - X-Envoy-Upstream-Service-Time: "722" + X-Envoy-Upstream-Service-Time: "552" X-Frame-Options: SAMEORIGIN X-Ntnx-Env: pc X-Ntnx-Product: pc.2023.4