Skip to content

Commit 544a786

Browse files
authored
Move CreateKubernetesPool to Pool and now is CreateKubernetesClusterPool (#169)
* Move CreateKubernetesPool to Pool and now is CreateKubernetesClusterPool * Fix lint error --------- Signed-off-by: Alejandro J. Nuñez Madrazo <[email protected]>
1 parent bc6515d commit 544a786

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

kubernetes.go

-10
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,6 @@ func (c *Client) UpdateKubernetesCluster(id string, i *KubernetesClusterConfig)
285285
return kubernetes, nil
286286
}
287287

288-
// CreateKubernetesPool update a single kubernetes cluster by its full ID
289-
func (c *Client) CreateKubernetesPool(id string, i *KubernetesClusterPoolConfig) (*KubernetesCluster, error) {
290-
i.Region = c.Region
291-
if _, err := c.SendPostRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools", id), i); err != nil {
292-
return nil, decodeError(err)
293-
}
294-
295-
return c.FindKubernetesCluster(id)
296-
}
297-
298288
// ListKubernetesMarketplaceApplications returns all application inside marketplace
299289
func (c *Client) ListKubernetesMarketplaceApplications() ([]KubernetesMarketplaceApplication, error) {
300290
resp, err := c.SendGetRequest("/v2/kubernetes/applications")

pool.go

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ func (c *Client) ListKubernetesClusterPools(cid string) ([]KubernetesPool, error
3434
return pools, nil
3535
}
3636

37+
// CreateKubernetesClusterPool update a single kubernetes cluster by its full ID
38+
func (c *Client) CreateKubernetesClusterPool(id string, i *KubernetesClusterPoolUpdateConfig) (*SimpleResponse, error) {
39+
i.Region = c.Region
40+
resp, err := c.SendPostRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools", id), i)
41+
if err != nil {
42+
return nil, decodeError(err)
43+
}
44+
return c.DecodeSimpleResponse(resp)
45+
}
46+
3747
// GetKubernetesClusterPool returns a pool for a kubernetes cluster
3848
func (c *Client) GetKubernetesClusterPool(cid, pid string) (*KubernetesPool, error) {
3949
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/kubernetes/clusters/%s/pools/%s", cid, pid))

pool_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ import (
77
corev1 "k8s.io/api/core/v1"
88
)
99

10+
func TestCreateKubernetesClusterPool(t *testing.T) {
11+
client, server, _ := NewClientForTesting(map[string]string{
12+
"/v2/kubernetes/clusters/e733ea47-cc80-443b-b3f2-cccfe7a61ef5/pools": `{"result": "success"}`,
13+
})
14+
defer server.Close()
15+
16+
newPool := &KubernetesClusterPoolUpdateConfig{
17+
ID: "8a849cc5-bd51-45ce-814a-c378b09dcb06",
18+
Count: 3,
19+
Size: "g4s.kube.small",
20+
Labels: map[string]string{},
21+
Taints: []corev1.Taint{},
22+
Region: "LON1",
23+
}
24+
25+
got, err := client.CreateKubernetesClusterPool("e733ea47-cc80-443b-b3f2-cccfe7a61ef5", newPool)
26+
if err != nil {
27+
t.Errorf("Request returned an error: %s", err)
28+
return
29+
}
30+
31+
expected := &SimpleResponse{Result: "success"}
32+
if !reflect.DeepEqual(got, expected) {
33+
t.Errorf("Expected %+v, got %+v", expected, got)
34+
}
35+
}
1036
func TestGetKubernetesPool(t *testing.T) {
1137
client, server, _ := NewClientForTesting(map[string]string{
1238
"/v2/kubernetes/clusters/e733ea47-cc80-443b-b3f2-cccfe7a61ef5/pools/fad8638d-efac-41e0-8787-23d37d845685": `{

0 commit comments

Comments
 (0)