Skip to content

Commit

Permalink
Merge pull request #9018 from spotinst/feature-grace-period
Browse files Browse the repository at this point in the history
Spotinst: Support for Grace Period in Ocean Cluster
  • Loading branch information
k8s-ci-robot committed Apr 28, 2020
2 parents 0adf32f + 1ecf559 commit 8d14693
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/spotinst/spotinst-sdk-go v1.43.0
github.com/spotinst/spotinst-sdk-go v1.49.0
github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.20.0
github.com/vmware/govmomi v0.20.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spotinst/spotinst-sdk-go v1.43.0 h1:ba5LQrYHQaq6TeC2JR3Hau7pbymVFScj3zoDxhbRphs=
github.com/spotinst/spotinst-sdk-go v1.43.0/go.mod h1:nWi2DyjUi1WUZclpsqZFXvImsU0T39ppqqHwC4/T5mw=
github.com/spotinst/spotinst-sdk-go v1.49.0 h1:JmsLlsgd/cCKpcn04HrParo5r34owDzIC12IW1SpSEs=
github.com/spotinst/spotinst-sdk-go v1.49.0/go.mod h1:nWi2DyjUi1WUZclpsqZFXvImsU0T39ppqqHwC4/T5mw=
github.com/storageos/go-api v0.0.0-20180912212459-343b3eff91fc/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwbJPZqfmtCXxFm9ckv0agOY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
Expand Down
11 changes: 11 additions & 0 deletions pkg/model/spotinstmodel/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const (
// be enabled.
InstanceGroupLabelFallbackToOnDemand = "spotinst.io/fallback-to-ondemand"

// InstanceGroupLabelGracePeriod is the metadata label used on the
// instance group to specify a period of time, in seconds, that Ocean
// should wait before applying instance health checks.
InstanceGroupLabelGracePeriod = "spotinst.io/grace-period"

// InstanceGroupLabelHealthCheckType is the metadata label used on the
// instance group to specify the type of the health check that should be used.
InstanceGroupLabelHealthCheckType = "spotinst.io/health-check-type"
Expand Down Expand Up @@ -355,6 +360,12 @@ func (b *InstanceGroupModelBuilder) buildOcean(c *fi.ModelBuilderContext, igs ..
return err
}

case InstanceGroupLabelGracePeriod:
ocean.GracePeriod, err = parseInt(v)
if err != nil {
return err
}

case InstanceGroupLabelOceanInstanceTypesWhitelist:
ocean.InstanceTypesWhitelist, err = parseStringSlice(v)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions upup/pkg/fi/cloudup/spotinsttasks/ocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Ocean struct {
SpotPercentage *float64
UtilizeReservedInstances *bool
FallbackToOnDemand *bool
GracePeriod *int64
InstanceTypesWhitelist []string
InstanceTypesBlacklist []string
Tags map[string]string
Expand Down Expand Up @@ -145,6 +146,10 @@ func (o *Ocean) Find(c *fi.Context) (*Ocean, error) {
actual.SpotPercentage = strategy.SpotPercentage
actual.FallbackToOnDemand = strategy.FallbackToOnDemand
actual.UtilizeReservedInstances = strategy.UtilizeReservedInstances

if strategy.GracePeriod != nil {
actual.GracePeriod = fi.Int64(int64(fi.IntValue(strategy.GracePeriod)))
}
}
}

Expand Down Expand Up @@ -366,6 +371,10 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
ocean.Strategy.SetSpotPercentage(e.SpotPercentage)
ocean.Strategy.SetFallbackToOnDemand(e.FallbackToOnDemand)
ocean.Strategy.SetUtilizeReservedInstances(e.UtilizeReservedInstances)

if e.GracePeriod != nil {
ocean.Strategy.SetGracePeriod(fi.Int(int(*e.GracePeriod)))
}
}

// Compute.
Expand Down Expand Up @@ -610,6 +619,17 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
changes.UtilizeReservedInstances = nil
changed = true
}

// Grace period.
if changes.GracePeriod != nil {
if ocean.Strategy == nil {
ocean.Strategy = new(aws.Strategy)
}

ocean.Strategy.SetGracePeriod(fi.Int(int(*e.GracePeriod)))
changes.GracePeriod = nil
changed = true
}
}

// Compute.
Expand Down Expand Up @@ -977,6 +997,7 @@ type terraformOceanStrategy struct {
SpotPercentage *float64 `json:"spot_percentage,omitempty" cty:"spot_percentage"`
FallbackToOnDemand *bool `json:"fallback_to_ondemand,omitempty" cty:"fallback_to_ondemand"`
UtilizeReservedInstances *bool `json:"utilize_reserved_instances,omitempty" cty:"utilize_reserved_instances"`
GracePeriod *int64 `json:"grace_period,omitempty" cty:"grace_period"`
}

type terraformOceanLaunchSpec struct {
Expand Down Expand Up @@ -1012,6 +1033,7 @@ func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Oce
SpotPercentage: e.SpotPercentage,
FallbackToOnDemand: e.FallbackToOnDemand,
UtilizeReservedInstances: e.UtilizeReservedInstances,
GracePeriod: e.GracePeriod,
},
terraformOceanLaunchSpec: &terraformOceanLaunchSpec{},
}
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/spotinst/spotinst-sdk-go/NOTICE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ github.com/spf13/jwalterweatherman
github.com/spf13/pflag
# github.com/spf13/viper v1.4.0
github.com/spf13/viper
# github.com/spotinst/spotinst-sdk-go v1.43.0
# github.com/spotinst/spotinst-sdk-go v1.49.0
github.com/spotinst/spotinst-sdk-go/service/elastigroup
github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/aws
github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure
Expand Down

0 comments on commit 8d14693

Please sign in to comment.