diff --git a/client/k8s/v2/k8s/pools.go b/client/k8s/v2/k8s/pools.go index 5402f17a..e2ad38c1 100644 --- a/client/k8s/v2/k8s/pools.go +++ b/client/k8s/v2/k8s/pools.go @@ -166,16 +166,11 @@ var poolCreateSubCommand = cli.Command{ } tc := getTaskClient(c, client) return utils.WaitTaskAndShowResult(c, tc, results, true, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterName, poolName).Extract() + pool, err := pools.Get(client, clusterName, poolName).Extract() if err != nil { return nil, fmt.Errorf("cannot create pool with name: %s. Error: %w", poolName, err) } - switch err.(type) { - case gcorecloud.ErrDefault404: - return nil, nil - default: - return nil, err - } + return pool, err }) }, } @@ -192,11 +187,6 @@ var poolUpdateSubCommand = cli.Command{ Usage: "Cluster name", Required: true, }, - &cli.IntFlag{ - Name: "node-count", - Usage: "Current number of pool nodes", - Required: false, - }, &cli.IntFlag{ Name: "min-node-count", Usage: "Minimum number of pool nodes", @@ -227,7 +217,6 @@ var poolUpdateSubCommand = cli.Command{ } opts := pools.UpdateOpts{ AutoHealingEnabled: c.Bool("auto-healing-enabled"), - NodeCount: c.Int("node-count"), MinNodeCount: c.Int("min-node-count"), MaxNodeCount: c.Int("max-node-count"), } @@ -279,16 +268,11 @@ var poolResizeSubCommand = cli.Command{ } tc := getTaskClient(c, client) return utils.WaitTaskAndShowResult(c, tc, results, true, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterName, poolName).Extract() + pool, err := pools.Get(client, clusterName, poolName).Extract() if err != nil { return nil, fmt.Errorf("cannot resize pool with name: %s. Error: %w", poolName, err) } - switch err.(type) { - case gcorecloud.ErrDefault404: - return nil, nil - default: - return nil, err - } + return pool, err }) }, } diff --git a/gcore/k8s/v2/pools/requests.go b/gcore/k8s/v2/pools/requests.go index df27cc84..96d972fd 100644 --- a/gcore/k8s/v2/pools/requests.go +++ b/gcore/k8s/v2/pools/requests.go @@ -48,9 +48,8 @@ type UpdateOptsBuilder interface { // UpdateOpts represents options used to update a pool. type UpdateOpts struct { AutoHealingEnabled bool `json:"auto_healing_enabled,omitempty"` - NodeCount int `json:"node_count,omitempty" validate:"omitempty,gt=0,lte=20,gtefield=MinNodeCount,ltefield=MaxNodeCount"` - MinNodeCount int `json:"min_node_count,omitempty" validate:"omitempty,gt=0,lte=20,ltefield=NodeCount,ltefield=MaxNodeCount"` - MaxNodeCount int `json:"max_node_count,omitempty" validate:"omitempty,gt=0,lte=20,gtefield=NodeCount,gtefield=MinNodeCount"` + MinNodeCount int `json:"min_node_count,omitempty" validate:"omitempty,gt=0,lte=20,ltefield=MaxNodeCount"` + MaxNodeCount int `json:"max_node_count,omitempty" validate:"omitempty,gt=0,lte=20,gtefield=MinNodeCount"` } // Validate UpdateOpts diff --git a/gcore/k8s/v2/pools/testing/fixtures.go b/gcore/k8s/v2/pools/testing/fixtures.go index 10b973db..1a023022 100644 --- a/gcore/k8s/v2/pools/testing/fixtures.go +++ b/gcore/k8s/v2/pools/testing/fixtures.go @@ -73,7 +73,6 @@ const GetResponse = ` const UpdateRequest = ` { - "node_count": 2, "min_mode_count": 1, "max_mode_count": 3, } diff --git a/gcore/k8s/v2/pools/testing/options_test.go b/gcore/k8s/v2/pools/testing/options_test.go index 984f4c83..3c0d5596 100644 --- a/gcore/k8s/v2/pools/testing/options_test.go +++ b/gcore/k8s/v2/pools/testing/options_test.go @@ -52,43 +52,20 @@ func TestCreateOpts(t *testing.T) { func TestUpdateOpts(t *testing.T) { options := pools.UpdateOpts{ MinNodeCount: 5, - NodeCount: 4, MaxNodeCount: 3, } _, err := options.ToClusterPoolUpdateMap() require.Error(t, err) - require.Contains(t, err.Error(), "NodeCount") require.Contains(t, err.Error(), "MinNodeCount") require.Contains(t, err.Error(), "MaxNodeCount") - options = pools.UpdateOpts{ - MinNodeCount: 5, - NodeCount: 3, - } - - _, err = options.ToClusterPoolUpdateMap() - require.Error(t, err) - require.Contains(t, err.Error(), "NodeCount") - require.Contains(t, err.Error(), "MinNodeCount") - - options = pools.UpdateOpts{ - NodeCount: 5, - MaxNodeCount: 3, - } - - _, err = options.ToClusterPoolUpdateMap() - require.Error(t, err) - require.Contains(t, err.Error(), "NodeCount") - require.Contains(t, err.Error(), "MaxNodeCount") - options = pools.UpdateOpts{} _, err = options.ToClusterPoolUpdateMap() require.NoError(t, err) options = pools.UpdateOpts{ - NodeCount: 2, MinNodeCount: 2, MaxNodeCount: 2, } diff --git a/gcore/k8s/v2/pools/testing/requests_test.go b/gcore/k8s/v2/pools/testing/requests_test.go index a5426e35..14bb1ae0 100644 --- a/gcore/k8s/v2/pools/testing/requests_test.go +++ b/gcore/k8s/v2/pools/testing/requests_test.go @@ -179,7 +179,7 @@ func TestUpdate(t *testing.T) { w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - _, err := fmt.Fprint(w, CreateResponse) + _, err := fmt.Fprint(w, UpdateResponse) if err != nil { log.Error(err) } @@ -189,14 +189,14 @@ func TestUpdate(t *testing.T) { options := pools.UpdateOpts{ MinNodeCount: 1, - NodeCount: 2, MaxNodeCount: 3, } - tasks, err := pools.Update(client, Cluster1Name, Pool1.Name, options).Extract() + ct, err := pools.Update(client, Cluster1Name, Pool1.Name, options).Extract() require.NoError(t, err) - require.Equal(t, Tasks1, *tasks) + require.Equal(t, 1, ct.MinNodeCount) + require.Equal(t, 3, ct.MaxNodeCount) } func TestDelete(t *testing.T) {