Skip to content

Commit

Permalink
Merge pull request #89 from civo/pool-update
Browse files Browse the repository at this point in the history
Add update node pool function and test
  • Loading branch information
vishalanarase authored Apr 28, 2022
2 parents b0c6ad0 + 574976e commit 66437a4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions fake_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
15 changes: 15 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 66437a4

Please sign in to comment.