diff --git a/docs/getting_started/spot-ocean.md b/docs/getting_started/spot-ocean.md index 767ea796f0..e1ddcb9314 100644 --- a/docs/getting_started/spot-ocean.md +++ b/docs/getting_started/spot-ocean.md @@ -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 diff --git a/go.mod b/go.mod index 5231b5436d..844c54e091 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index aff746a6ca..b65a77a9b1 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/model/spotinstmodel/instance_group.go b/pkg/model/spotinstmodel/instance_group.go index 7f2e39a346..e6943b5406 100644 --- a/pkg/model/spotinstmodel/instance_group.go +++ b/pkg/model/spotinstmodel/instance_group.go @@ -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 + } } } diff --git a/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go b/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go index 4b8d929368..d4a8e6bad7 100644 --- a/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go +++ b/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go @@ -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) } diff --git a/vendor/github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws/launch_spec.go b/vendor/github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws/launch_spec.go index 4b919be14c..4177219447 100644 --- a/vendor/github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws/launch_spec.go +++ b/vendor/github.com/spotinst/spotinst-sdk-go/service/ocean/providers/aws/launch_spec.go @@ -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 diff --git a/vendor/github.com/spotinst/spotinst-sdk-go/spotinst/version.go b/vendor/github.com/spotinst/spotinst-sdk-go/spotinst/version.go index fa6b299510..16fe6ce4e9 100644 --- a/vendor/github.com/spotinst/spotinst-sdk-go/spotinst/version.go +++ b/vendor/github.com/spotinst/spotinst-sdk-go/spotinst/version.go @@ -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" diff --git a/vendor/modules.txt b/vendor/modules.txt index 12d198b0a7..925aee6a25 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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