Skip to content

Commit

Permalink
MKAAS-656 remove node_count from k8s cluster pool UpdateOpts (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Grzegorz Bernady <grzegorz.bernady@gcore.com>
  • Loading branch information
gbernady and gbernady authored Sep 4, 2023
1 parent 476026b commit 901e53a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 51 deletions.
24 changes: 4 additions & 20 deletions client/k8s/v2/k8s/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
},
}
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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
})
},
}
Expand Down
5 changes: 2 additions & 3 deletions gcore/k8s/v2/pools/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion gcore/k8s/v2/pools/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const GetResponse = `

const UpdateRequest = `
{
"node_count": 2,
"min_mode_count": 1,
"max_mode_count": 3,
}
Expand Down
23 changes: 0 additions & 23 deletions gcore/k8s/v2/pools/testing/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
8 changes: 4 additions & 4 deletions gcore/k8s/v2/pools/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down

0 comments on commit 901e53a

Please sign in to comment.