Skip to content

Commit

Permalink
add args to fetch list method
Browse files Browse the repository at this point in the history
  • Loading branch information
ayessymkanov committed Nov 21, 2023
1 parent 7168240 commit 812423a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 57 deletions.
44 changes: 3 additions & 41 deletions karbon/karbon_cluster_registration_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package karbon

import (
"context"
"fmt"
"net/http"

"github.com/google/uuid"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions karbon/karbon_cluster_registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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{},
Expand All @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions karbon/mocks/TestKarbonGetK8sRegistrationList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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
req:
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
Expand All @@ -28,21 +28,21 @@ 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
X-Permitted-Cross-Domain-Policies: master-only
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
Expand Down
4 changes: 2 additions & 2 deletions karbon/mocks/TestKarbonGetK8sRegistrationListEmpty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions karbon/mocks/TestKarbonGetK8sRegistrationListPage1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ 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
X-Permitted-Cross-Domain-Policies: master-only
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
Expand Down
4 changes: 2 additions & 2 deletions karbon/mocks/TestKarbonGetK8sRegistrationListPage2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 812423a

Please sign in to comment.