Skip to content

Commit

Permalink
V1: nodegroup autoscale support (#53)
Browse files Browse the repository at this point in the history
* V1: nodegroup autoscale support

Add EnableAutoscale, AutoscaleMinNodes, AutoscaleMaxNodes fields
into View, CreateOpts and UpdateOpts structs in the nodegroup package.

Update testing fixtures.

Add IntToPtr helper in testutils package.

* Disable "maligned" linter for the nodegroup View
  • Loading branch information
kolsean authored Sep 3, 2020
1 parent e90912b commit 3ed49a3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/testutils/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ package testutils
func BoolToPtr(v bool) *bool {
return &v
}

// IntToPtr can be used to convert integer value to integer pointer.
func IntToPtr(v int) *int {
return &v
}
19 changes: 19 additions & 0 deletions pkg/v1/nodegroup/requests_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ type CreateOpts struct {

// Taints represents a list of nodegroup taints.
Taints []Taint `json:"taints"`

// EnableAutoscale reflects if the nodegroup is allowed to be scaled automatically.
// Disabled by default.
EnableAutoscale *bool `json:"enable_autoscale,omitempty"`

// AutoscaleMinNodes represents minimum possible number of worker nodes in the nodegroup.
AutoscaleMinNodes *int `json:"autoscale_min_nodes,omitempty"`

// AutoscaleMaxNodes represents maximum possible number of worker nodes in the nodegroup.
AutoscaleMaxNodes *int `json:"autoscale_max_nodes,omitempty"`
}

// ResizeOpts represents options for the nodegroup Resize request.
Expand All @@ -56,4 +66,13 @@ type UpdateOpts struct {
// Labels represents an object containing a set of Kubernetes labels that will be applied
// for each node in the group. The keys must be user-defined.
Labels map[string]string `json:"labels"`

// EnableAutoscale reflects if the nodegroup is allowed to be scaled automatically.
EnableAutoscale *bool `json:"enable_autoscale,omitempty"`

// AutoscaleMinNodes represents minimum possible number of worker nodes in the nodegroup.
AutoscaleMinNodes *int `json:"autoscale_min_nodes,omitempty"`

// AutoscaleMaxNodes represents maximum possible number of worker nodes in the nodegroup.
AutoscaleMaxNodes *int `json:"autoscale_max_nodes,omitempty"`
}
10 changes: 10 additions & 0 deletions pkg/v1/nodegroup/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/selectel/mks-go/pkg/v1/node"
)

// nolint:maligned
// View represents an unmarshalled nodegroup body from an API response.
type View struct {
// ID is the identifier of the nodegroup.
Expand Down Expand Up @@ -44,6 +45,15 @@ type View struct {

// Taints represents a list of nodegroup taints.
Taints []Taint `json:"taints"`

// EnableAutoscale reflects if the nodegroup is allowed to be scaled automatically.
EnableAutoscale bool `json:"enable_autoscale"`

// AutoscaleMinNodes represents minimum possible number of worker nodes in the nodegroup.
AutoscaleMinNodes int `json:"autoscale_min_nodes"`

// AutoscaleMaxNodes represents maximum possible number of worker nodes in the nodegroup.
AutoscaleMaxNodes int `json:"autoscale_max_nodes"`
}

// TaintEffect represents an effect of the node's taint.
Expand Down
29 changes: 25 additions & 4 deletions pkg/v1/nodegroup/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testing
import (
"time"

"github.com/selectel/mks-go/pkg/testutils"
"github.com/selectel/mks-go/pkg/v1/node"
"github.com/selectel/mks-go/pkg/v1/nodegroup"
)
Expand Down Expand Up @@ -40,7 +41,10 @@ const testGetNodegroupResponseRaw = `
"value": "test-value-0",
"effect": "NoSchedule"
}
]
],
"enable_autoscale": false,
"autoscale_min_nodes": 0,
"autoscale_max_nodes": 0
}
}
`
Expand Down Expand Up @@ -80,6 +84,9 @@ var expectedGetNodegroupResponse = &nodegroup.View{
Effect: nodegroup.NoScheduleEffect,
},
},
EnableAutoscale: false,
AutoscaleMinNodes: 0,
AutoscaleMaxNodes: 0,
}

// testListNodegroupsResponseRaw represents a raw response from the List method.
Expand Down Expand Up @@ -116,7 +123,10 @@ const testListNodegroupsResponseRaw = `
"value": "test-value-0",
"effect": "NoSchedule"
}
]
],
"enable_autoscale": false,
"autoscale_min_nodes": 0,
"autoscale_max_nodes": 0
}
]
}
Expand Down Expand Up @@ -156,6 +166,9 @@ var expectedListNodegroupsResponse = []*nodegroup.View{
Effect: nodegroup.NoScheduleEffect,
},
},
EnableAutoscale: false,
AutoscaleMinNodes: 0,
AutoscaleMaxNodes: 0,
},
}

Expand All @@ -179,7 +192,10 @@ const testCreateNodegroupOptsRaw = `
"value": "test-value-0",
"effect": "NoSchedule"
}
]
],
"enable_autoscale": true,
"autoscale_min_nodes": 1,
"autoscale_max_nodes": 10
}
}
`
Expand All @@ -204,6 +220,9 @@ var testCreateNodegroupOpts = &nodegroup.CreateOpts{
Effect: nodegroup.NoScheduleEffect,
},
},
EnableAutoscale: testutils.BoolToPtr(true),
AutoscaleMinNodes: testutils.IntToPtr(1),
AutoscaleMaxNodes: testutils.IntToPtr(10),
}

// testUpdateNodegroupOptsRaw represents marshalled options for the Update request.
Expand All @@ -212,7 +231,8 @@ const testUpdateNodegroupOptsRaw = `
"nodegroup": {
"labels": {
"test-label-key": "test-label-value"
}
},
"enable_autoscale": false
}
}
`
Expand All @@ -223,6 +243,7 @@ var testUpdateNodegroupOpts = &nodegroup.UpdateOpts{
Labels: map[string]string{
"test-label-key": "test-label-value",
},
EnableAutoscale: testutils.BoolToPtr(false),
}

// testResizeNodegroupOptsRaw represents marshalled options for the Resize request.
Expand Down

0 comments on commit 3ed49a3

Please sign in to comment.