feat(spot/ocean): configure resource limits

This commit is contained in:
liranp 2020-11-07 20:27:11 +02:00
parent 6a57543f6e
commit fce6a22755
No known key found for this signature in database
GPG Key ID: D5F03857002C1A93
5 changed files with 92 additions and 15 deletions

View File

@ -18,7 +18,7 @@ The following experimental features are currently available:
* `+KeepLaunchConfigurations` - Prevents garbage collection of old launch configurations
* `+Spotinst` - Enables the use of the Spot integration
* `+SpotinstOcean` - Enables the use of the Spot Ocean integration
* `+SpotinstHybrid` - Toogles between hybrid and full instance group implementations
* `+SpotinstHybrid` - Toggles between hybrid and full instance group implementations
* `-SpotinstController` - Toggles the installation of the Spot controller addon off
* `+SkipEtcdVersionCheck` - Bypasses the check that etcd-manager is using a supported etcd version
* `+TerraformJSON` - Produce kubernetes.tf.json file instead of writing HCLv2 syntax. Can be consumed by terraform 0.12+

View File

@ -167,10 +167,12 @@ metadata:
| `spotinst.io/autoscaler-cooldown` | Specify a period of time, in seconds, that Ocean should wait between scaling actions. | `300` |
| `spotinst.io/autoscaler-scale-down-max-percentage` | Specify the maximum scale down percentage. | none |
| `spotinst.io/autoscaler-scale-down-evaluation-periods` | Specify the number of evaluation periods that should accumulate before a scale down action takes place. | `5` |
| `spotinst.io/autoscaler-resource-limits-max-vcpu` | Specify the maximum number of virtual CPUs that can be allocated to the cluster. | none |
| `spotinst.io/autoscaler-resource-limits-max-memory` | Specify the maximum amount of total physical memory (in GiB units) that can be allocated to the cluster. | none |
## Documentation
If you're new to [Spot](https://spot.io/) and want to get started, please checkout our [Getting Started](https://help.spot.io/getting-started-with-spotinst/) guide, available on the [Spot Help Center](https://help.spot.io/) website.
If you're new to [Spot](https://spot.io/) and want to get started, please checkout our [Getting Started](https://docs.spot.io/connect-your-cloud-provider/) guide, available on the [Spot Documentation](https://docs.spot.io/) website.
## Getting Help

View File

@ -107,6 +107,11 @@ const (
// instance group to specify the scale down configuration used by the auto scaler.
InstanceGroupLabelAutoScalerScaleDownMaxPercentage = "spotinst.io/autoscaler-scale-down-max-percentage"
InstanceGroupLabelAutoScalerScaleDownEvaluationPeriods = "spotinst.io/autoscaler-scale-down-evaluation-periods"
// InstanceGroupLabelAutoScalerResourceLimits* are the metadata labels used on the
// instance group to specify the resource limits configuration used by the auto scaler.
InstanceGroupLabelAutoScalerResourceLimitsMaxVCPU = "spotinst.io/autoscaler-resource-limits-max-vcpu"
InstanceGroupLabelAutoScalerResourceLimitsMaxMemory = "spotinst.io/autoscaler-resource-limits-max-memory"
)
// InstanceGroupModelBuilder configures InstanceGroup objects
@ -851,6 +856,30 @@ func (b *InstanceGroupModelBuilder) buildAutoScalerOpts(clusterID string, ig *ko
}
opts.Down.EvaluationPeriods = fi.Int(int(fi.Int64Value(v)))
}
case InstanceGroupLabelAutoScalerResourceLimitsMaxVCPU:
{
v, err := parseInt(v)
if err != nil {
return nil, err
}
if opts.ResourceLimits == nil {
opts.ResourceLimits = new(spotinsttasks.AutoScalerResourceLimitsOpts)
}
opts.ResourceLimits.MaxVCPU = fi.Int(int(fi.Int64Value(v)))
}
case InstanceGroupLabelAutoScalerResourceLimitsMaxMemory:
{
v, err := parseInt(v)
if err != nil {
return nil, err
}
if opts.ResourceLimits == nil {
opts.ResourceLimits = new(spotinsttasks.AutoScalerResourceLimitsOpts)
}
opts.ResourceLimits.MaxMemory = fi.Int(int(fi.Int64Value(v)))
}
}
}

View File

@ -81,13 +81,14 @@ type RootVolumeOpts struct {
}
type AutoScalerOpts struct {
Enabled *bool
ClusterID *string
Cooldown *int
Labels map[string]string
Taints []*corev1.Taint
Headroom *AutoScalerHeadroomOpts
Down *AutoScalerDownOpts
Enabled *bool
ClusterID *string
Cooldown *int
Labels map[string]string
Taints []*corev1.Taint
Headroom *AutoScalerHeadroomOpts
Down *AutoScalerDownOpts
ResourceLimits *AutoScalerResourceLimitsOpts
}
type AutoScalerHeadroomOpts struct {
@ -102,6 +103,11 @@ type AutoScalerDownOpts struct {
EvaluationPeriods *int
}
type AutoScalerResourceLimitsOpts struct {
MaxVCPU *int
MaxMemory *int
}
var _ fi.Task = &Elastigroup{}
var _ fi.CompareWithID = &Elastigroup{}
var _ fi.HasDependencies = &Elastigroup{}
@ -1393,12 +1399,13 @@ type terraformElastigroupIntegration struct {
}
type terraformAutoScaler struct {
Enabled *bool `json:"autoscale_is_enabled,omitempty" cty:"autoscale_is_enabled"`
AutoConfig *bool `json:"autoscale_is_auto_config,omitempty" cty:"autoscale_is_auto_config"`
Cooldown *int `json:"autoscale_cooldown,omitempty" cty:"autoscale_cooldown"`
Headroom *terraformAutoScalerHeadroom `json:"autoscale_headroom,omitempty" cty:"autoscale_headroom"`
Down *terraformAutoScalerDown `json:"autoscale_down,omitempty" cty:"autoscale_down"`
Labels []*terraformKV `json:"autoscale_labels,omitempty" cty:"autoscale_labels"`
Enabled *bool `json:"autoscale_is_enabled,omitempty" cty:"autoscale_is_enabled"`
AutoConfig *bool `json:"autoscale_is_auto_config,omitempty" cty:"autoscale_is_auto_config"`
Cooldown *int `json:"autoscale_cooldown,omitempty" cty:"autoscale_cooldown"`
Headroom *terraformAutoScalerHeadroom `json:"autoscale_headroom,omitempty" cty:"autoscale_headroom"`
Down *terraformAutoScalerDown `json:"autoscale_down,omitempty" cty:"autoscale_down"`
ResourceLimits *terraformAutoScalerResourceLimits `json:"resource_limits,omitempty" cty:"resource_limits"`
Labels []*terraformKV `json:"autoscale_labels,omitempty" cty:"autoscale_labels"`
}
type terraformAutoScalerHeadroom struct {
@ -1413,6 +1420,11 @@ type terraformAutoScalerDown struct {
EvaluationPeriods *int `json:"evaluation_periods,omitempty" cty:"evaluation_periods"`
}
type terraformAutoScalerResourceLimits struct {
MaxVCPU *int `json:"max_vcpu,omitempty" cty:"max_vcpu"`
MaxMemory *int `json:"max_memory_gib,omitempty" cty:"max_memory_gib"`
}
type terraformKV struct {
Key *string `json:"key" cty:"key"`
Value *string `json:"value" cty:"value"`

View File

@ -312,6 +312,14 @@ func (o *Ocean) Find(c *fi.Context) (*Ocean, error) {
EvaluationPeriods: down.EvaluationPeriods,
}
}
// Resource limits.
if limits := ocean.AutoScaler.ResourceLimits; limits != nil {
actual.AutoScalerOpts.ResourceLimits = &AutoScalerResourceLimitsOpts{
MaxVCPU: limits.MaxVCPU,
MaxMemory: limits.MaxMemoryGiB,
}
}
}
}
@ -535,6 +543,14 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
}
}
// Resource limits.
if limits := opts.ResourceLimits; limits != nil {
autoScaler.ResourceLimits = &aws.AutoScalerResourceLimits{
MaxVCPU: limits.MaxVCPU,
MaxMemoryGiB: limits.MaxMemory,
}
}
ocean.SetAutoScaler(autoScaler)
}
}
@ -961,6 +977,16 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
autoScaler.SetDown(nil)
}
// Resource limits.
if limits := opts.ResourceLimits; limits != nil {
autoScaler.ResourceLimits = &aws.AutoScalerResourceLimits{
MaxVCPU: limits.MaxVCPU,
MaxMemoryGiB: limits.MaxMemory,
}
} else if a.AutoScalerOpts.ResourceLimits != nil {
autoScaler.SetResourceLimits(nil)
}
ocean.SetAutoScaler(autoScaler)
changed = true
}
@ -1180,6 +1206,14 @@ func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Oce
}
}
// Resource limits.
if limits := opts.ResourceLimits; limits != nil {
tf.AutoScaler.ResourceLimits = &terraformAutoScalerResourceLimits{
MaxVCPU: limits.MaxVCPU,
MaxMemory: limits.MaxVCPU,
}
}
// Ignore capacity changes because the auto scaler updates the
// desired capacity overtime.
if fi.BoolValue(tf.AutoScaler.Enabled) {