From 3f7ec9df4c17720186620225edf91c58a3a8d435 Mon Sep 17 00:00:00 2001 From: gm-data <104019354+gm-data@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:44:59 -0500 Subject: [PATCH] Add GetClusterConfig --- cloudability/containers.go | 10 ++++++++++ cloudability/containers_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/cloudability/containers.go b/cloudability/containers.go index 333e546..e972e3f 100644 --- a/cloudability/containers.go +++ b/cloudability/containers.go @@ -50,6 +50,16 @@ func (e ContainersEndpoint) GetCluster(id string) (*Cluster, error) { return nil, err } +// GetClusterConfig - Get an existing cluster config by ID +func (e ContainersEndpoint) GetClusterConfig(id string) (string, error) { + var result string + err := e.get(e, "provisioning/"+id+"/config", &result) + if err != nil { + return "", err + } + return result, nil +} + // NewCluster - Create a new cluster. func (e *ContainersEndpoint) NewCluster(clusterProvisioning *Cluster) (*Cluster, error) { clusterProvisioningPayload := new(clusterPayload) diff --git a/cloudability/containers_test.go b/cloudability/containers_test.go index 9181228..2796130 100644 --- a/cloudability/containers_test.go +++ b/cloudability/containers_test.go @@ -29,6 +29,35 @@ func TestGetCluster(t *testing.T) { } } +func TestGetClusterConfig(t *testing.T) { + mockYAML := ` +apiVersion: v1 +kind: Namespace +metadata: + name: cloudability +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: cloudability + namespace: cloudability +` + + testServer := testAPI(t, "GET", "/containers/provisioning/1/config", mockYAML) + defer testServer.Close() + + testClient := NewClient("testapikey") + e := testClient.Containers() + e.BaseURL, _ = url.Parse(testServer.URL) + config, err := e.GetClusterConfig("1") + if err != nil { + t.Fail() + } + if config != mockYAML { + t.Fail() + } +} + func TestNewCluster(t *testing.T) { cluster := &Cluster{ ClusterName: "test-cluster-name",