Skip to content

Commit

Permalink
feat(spot/ocean): add support for grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
liranp committed Apr 28, 2020
1 parent 9dd6b1b commit 1ecf559
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 1ecf559

Please sign in to comment.