feat(spot/ocean): new label: spotinst.io/restrict-scale-down

This commit is contained in:
liranp 2021-01-12 11:35:28 +02:00
parent 06a533ed04
commit 9fe505abed
No known key found for this signature in database
GPG Key ID: D5F03857002C1A93
8 changed files with 51 additions and 5 deletions

View File

@ -171,6 +171,7 @@ metadata:
| `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 |
| `spotinst.io/restrict-scale-down` | Specify whether the scale-down activities should be restricted. | none |
## Documentation

2
go.mod
View File

@ -85,7 +85,7 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
github.com/spotinst/spotinst-sdk-go v1.75.0
github.com/spotinst/spotinst-sdk-go v1.76.0
github.com/stretchr/testify v1.6.1
github.com/weaveworks/mesh v0.0.0-20170419100114-1f158d31de55
github.com/zclconf/go-cty v1.3.1

4
go.sum
View File

@ -954,8 +954,8 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spotinst/spotinst-sdk-go v1.75.0 h1:4eg0J1STZPnLxPiIYYYq7DYrApIkpzBpJAgzjFIgQfs=
github.com/spotinst/spotinst-sdk-go v1.75.0/go.mod h1:sSRVZTSdUAPxeELD/urZkxcfU/DcxO1/UIdOxagqFBc=
github.com/spotinst/spotinst-sdk-go v1.76.0 h1:tlFKrUAu7h3FgZM3Xy7436XR5lYo5Q/uePEy0AX5Ydw=
github.com/spotinst/spotinst-sdk-go v1.76.0/go.mod h1:sSRVZTSdUAPxeELD/urZkxcfU/DcxO1/UIdOxagqFBc=
github.com/storageos/go-api v0.0.0-20180912212459-343b3eff91fc/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwbJPZqfmtCXxFm9ckv0agOY=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=

View File

@ -118,6 +118,10 @@ const (
// 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"
// InstanceGroupLabelRestrictScaleDown is the metadata label used on the
// instance group to specify whether the scale-down activities should be restricted.
InstanceGroupLabelRestrictScaleDown = "spotinst.io/restrict-scale-down"
)
// InstanceGroupModelBuilder configures InstanceGroup objects
@ -525,6 +529,12 @@ func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
if err != nil {
return err
}
case InstanceGroupLabelRestrictScaleDown:
launchSpec.RestrictScaleDown, err = parseBool(v)
if err != nil {
return err
}
}
}

View File

@ -50,6 +50,7 @@ type LaunchSpec struct {
Tags map[string]string
RootVolumeOpts *RootVolumeOpts
AutoScalerOpts *AutoScalerOpts
RestrictScaleDown *bool
Ocean *Ocean
}
@ -140,6 +141,7 @@ func (o *LaunchSpec) Find(c *fi.Context) (*LaunchSpec, error) {
ID: ocean.ID,
Name: ocean.Name,
}
actual.RestrictScaleDown = spec.RestrictScaleDown
// Image.
{
@ -460,6 +462,13 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
}
}
// Restrictions.
{
if fi.BoolValue(e.RestrictScaleDown) {
spec.SetRestrictScaleDown(e.RestrictScaleDown)
}
}
// Wrap the raw object as a LaunchSpec.
sp, err := spotinst.NewLaunchSpec(cloud.ProviderID(), spec)
if err != nil {
@ -665,6 +674,15 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
}
}
// Restrictions.
{
if changes.RestrictScaleDown != nil {
spec.SetRestrictScaleDown(e.RestrictScaleDown)
changes.RestrictScaleDown = nil
changed = true
}
}
empty := &LaunchSpec{}
if !reflect.DeepEqual(empty, changes) {
klog.Warningf("Not all changes applied to Launch Spec %q: %v", *spec.ID, changes)
@ -724,6 +742,7 @@ type terraformLaunchSpec struct {
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
ImageID *string `json:"image_id,omitempty" cty:"image_id"`
AssociatePublicIPAddress *bool `json:"associate_public_ip_address,omitempty" cty:"associate_public_ip_address"`
RestrictScaleDown *bool `json:"restrict_scale_down,omitempty" cty:"restrict_scale_down"`
RootVolumeSize *int32 `json:"root_volume_size,omitempty" cty:"root_volume_size"`
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
IAMInstanceProfile *terraform.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
@ -882,6 +901,13 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
}
}
// Restrictions.
{
if fi.BoolValue(e.RestrictScaleDown) {
tf.RestrictScaleDown = e.RestrictScaleDown
}
}
return t.RenderResource("spotinst_ocean_aws_launch_spec", *e.Name, tf)
}

View File

@ -33,6 +33,8 @@ type LaunchSpec struct {
Taints []*Taint `json:"taints,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
AssociatePublicIPAddress *bool `json:"associatePublicIpAddress,omitempty"`
RestrictScaleDown *bool `json:"restrictScaleDown,omitempty"`
// Read-only fields.
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
@ -491,6 +493,13 @@ func (o *LaunchSpec) SetAssociatePublicIPAddress(v *bool) *LaunchSpec {
return o
}
func (o *LaunchSpec) SetRestrictScaleDown(v *bool) *LaunchSpec {
if o.RestrictScaleDown = v; o.RestrictScaleDown == nil {
o.nullFields = append(o.nullFields, "RestrictScaleDown")
}
return o
}
// endregion
// region BlockDeviceMapping

View File

@ -1,7 +1,7 @@
package spotinst
// SDKVersion is the current version of the SDK.
const SDKVersion = "1.75.0"
const SDKVersion = "1.76.0"
// SDKName is the name of the SDK.
const SDKName = "spotinst-sdk-go"

2
vendor/modules.txt vendored
View File

@ -513,7 +513,7 @@ github.com/spf13/pflag
# github.com/spf13/viper v1.7.0
## explicit
github.com/spf13/viper
# github.com/spotinst/spotinst-sdk-go v1.75.0
# github.com/spotinst/spotinst-sdk-go v1.76.0
## explicit
github.com/spotinst/spotinst-sdk-go/service/elastigroup
github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/aws