From 574976e4c246a3ab170e986ddeb420952ee36118 Mon Sep 17 00:00:00 2001 From: Vishal Anarse Date: Thu, 28 Apr 2022 12:36:30 +0530 Subject: [PATCH] Add update node pool function and test Signed-off-by: Vishal Anarse --- fake_client.go | 33 +++++++++++++++++++++++++++++++++ fake_client_test.go | 7 +++++++ pool.go | 15 +++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/fake_client.go b/fake_client.go index 230c890..8bb6e98 100644 --- a/fake_client.go +++ b/fake_client.go @@ -107,6 +107,7 @@ type Clienter interface { GetKubernetesClusterPool(cid, pid string) (*KubernetesPool, error) FindKubernetesClusterPool(cid, search string) (*KubernetesPool, error) DeleteKubernetesClusterPoolInstance(cid, pid, id string) (*SimpleResponse, error) + UpdateKubernetesClusterPool(cid, pid string, config *KubernetesClusterPoolConfig) (*KubernetesPool, error) // Networks GetDefaultNetwork() (*Network, error) @@ -1715,3 +1716,35 @@ func (c *FakeClient) DeleteKubernetesClusterPoolInstance(cid, pid, id string) (* Result: "success", }, nil } + +// UpdateKubernetesClusterPool implemented in a fake way for automated tests +func (c *FakeClient) UpdateKubernetesClusterPool(cid, pid string, config *KubernetesClusterPoolConfig) (*KubernetesPool, error) { + clusterFound := false + poolFound := false + + pool := KubernetesPool{} + for _, cs := range c.Clusters { + if cs.ID == cid { + clusterFound = true + for _, p := range cs.Pools { + if p.ID == pid { + poolFound = true + p.Count = config.Count + pool = p + } + } + } + } + + if !clusterFound { + err := fmt.Errorf("unable to get kubernetes cluster %s", cid) + return nil, DatabaseKubernetesClusterNotFoundError.wrap(err) + } + + if !poolFound { + err := fmt.Errorf("unable to get kubernetes pool %s", pid) + return nil, DatabaseKubernetesClusterNotFoundError.wrap(err) + } + + return &pool, nil +} diff --git a/fake_client_test.go b/fake_client_test.go index e5c639a..5d5c07e 100644 --- a/fake_client_test.go +++ b/fake_client_test.go @@ -211,4 +211,11 @@ func TestKubernetesClustersPools(t *testing.T) { result, err := client.DeleteKubernetesClusterPoolInstance("9c89d8b9-463d-45f2-8928-455eb3f3726", "33de5de2-14fd-44ba-a621-f6efbeeb9639", "ad0dbf3f-4036-47f5-b33b-6822cf90799c0") g.Expect(err).To(BeNil()) g.Expect(string(result.Result)).To(Equal("success")) + + pc := KubernetesClusterPoolConfig{ + Count: 4, + } + pool, err = client.UpdateKubernetesClusterPool("9c89d8b9-463d-45f2-8928-455eb3f3726", "33de5de2-14fd-44ba-a621-f6efbeeb9639", &pc) + g.Expect(err).To(BeNil()) + g.Expect(pool.Count).To(Equal(4)) } diff --git a/pool.go b/pool.go index 6d450b5..df247d8 100644 --- a/pool.go +++ b/pool.go @@ -80,3 +80,18 @@ func (c *Client) DeleteKubernetesClusterPoolInstance(cid, pid, id string) (*Simp return c.DecodeSimpleResponse(resp) } + +// UpdateKubernetesClusterPool updates a pool for a kubernetes cluster +func (c *Client) UpdateKubernetesClusterPool(cid, pid string, config *KubernetesClusterPoolConfig) (*KubernetesPool, error) { + resp, err := c.SendPutRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools/%s", cid, pid), config) + if err != nil { + return nil, decodeError(err) + } + + pool := &KubernetesPool{} + if err := json.NewDecoder(bytes.NewReader(resp)).Decode(&pool); err != nil { + return nil, decodeError(err) + } + + return pool, nil +}