Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1: nodegroup autoscale support #53

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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