Skip to content

Commit

Permalink
Move CreateKubernetesPool to Pool and now is CreateKubernetesClusterP…
Browse files Browse the repository at this point in the history
…ool (#169)

* Move CreateKubernetesPool to Pool and now is CreateKubernetesClusterPool
* Fix lint error
---------

Signed-off-by: Alejandro J. Nuñez Madrazo <[email protected]>
  • Loading branch information
alejandrojnm authored Oct 3, 2023
1 parent bc6515d commit 544a786
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
10 changes: 0 additions & 10 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,6 @@ func (c *Client) UpdateKubernetesCluster(id string, i *KubernetesClusterConfig)
return kubernetes, nil
}

// CreateKubernetesPool update a single kubernetes cluster by its full ID
func (c *Client) CreateKubernetesPool(id string, i *KubernetesClusterPoolConfig) (*KubernetesCluster, error) {
i.Region = c.Region
if _, err := c.SendPostRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools", id), i); err != nil {
return nil, decodeError(err)
}

return c.FindKubernetesCluster(id)
}

// ListKubernetesMarketplaceApplications returns all application inside marketplace
func (c *Client) ListKubernetesMarketplaceApplications() ([]KubernetesMarketplaceApplication, error) {
resp, err := c.SendGetRequest("/v2/kubernetes/applications")
Expand Down
10 changes: 10 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func (c *Client) ListKubernetesClusterPools(cid string) ([]KubernetesPool, error
return pools, nil
}

// CreateKubernetesClusterPool update a single kubernetes cluster by its full ID
func (c *Client) CreateKubernetesClusterPool(id string, i *KubernetesClusterPoolUpdateConfig) (*SimpleResponse, error) {
i.Region = c.Region
resp, err := c.SendPostRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools", id), i)
if err != nil {
return nil, decodeError(err)
}
return c.DecodeSimpleResponse(resp)
}

// GetKubernetesClusterPool returns a pool for a kubernetes cluster
func (c *Client) GetKubernetesClusterPool(cid, pid string) (*KubernetesPool, error) {
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools/%s", cid, pid))
Expand Down
26 changes: 26 additions & 0 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ import (
corev1 "k8s.io/api/core/v1"
)

func TestCreateKubernetesClusterPool(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kubernetes/clusters/e733ea47-cc80-443b-b3f2-cccfe7a61ef5/pools": `{"result": "success"}`,
})
defer server.Close()

newPool := &KubernetesClusterPoolUpdateConfig{
ID: "8a849cc5-bd51-45ce-814a-c378b09dcb06",
Count: 3,
Size: "g4s.kube.small",
Labels: map[string]string{},
Taints: []corev1.Taint{},
Region: "LON1",
}

got, err := client.CreateKubernetesClusterPool("e733ea47-cc80-443b-b3f2-cccfe7a61ef5", newPool)
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}

expected := &SimpleResponse{Result: "success"}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestGetKubernetesPool(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/kubernetes/clusters/e733ea47-cc80-443b-b3f2-cccfe7a61ef5/pools/fad8638d-efac-41e0-8787-23d37d845685": `{
Expand Down

0 comments on commit 544a786

Please sign in to comment.