Merge pull request #9746 from spotinst/feat-launchspec-itypes

Spotinst: Support for Instance Types in Ocean Launch Spec
This commit is contained in:
Kubernetes Prow Robot 2020-08-13 13:30:22 -07:00 committed by GitHub
commit 847273b1b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 12 deletions

View File

@ -157,6 +157,7 @@ metadata:
| `spotinst.io/ocean-default-launchspec` | Specify whether to use the InstanceGroup's spec as the default Launch Spec for the Ocean cluster. | none |
| `spotinst.io/ocean-instance-types-whitelist` | Specify whether to whitelist specific instance types. | none |
| `spotinst.io/ocean-instance-types-blacklist` | Specify whether to blacklist specific instance types. | none |
| `spotinst.io/ocean-instance-types` | Specify a list of instance types that should be used by the Ocean Launch Spec. | none |
| `spotinst.io/autoscaler-disabled` | Specify whether the auto scaler should be disabled. | `false` |
| `spotinst.io/autoscaler-default-node-labels` | Specify whether default node labels should be set for the auto scaler. | `false` |
| `spotinst.io/autoscaler-headroom-cpu-per-unit` | Specify the number of CPUs to allocate for headroom. CPUs are denoted in millicores, where 1000 millicores = 1 vCPU. | none |

2
go.mod
View File

@ -93,7 +93,7 @@ require (
github.com/spf13/cobra v0.0.7
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/spotinst/spotinst-sdk-go v1.56.0
github.com/spotinst/spotinst-sdk-go v1.58.0
github.com/stretchr/testify v1.5.1
github.com/urfave/cli v1.20.0
github.com/weaveworks/mesh v0.0.0-20170419100114-1f158d31de55

4
go.sum
View File

@ -794,8 +794,8 @@ github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
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.56.0 h1:w7OnAWXWPxvOvqjYv4i0kN70KWGTNcyoNB72suIA30g=
github.com/spotinst/spotinst-sdk-go v1.56.0/go.mod h1:nWi2DyjUi1WUZclpsqZFXvImsU0T39ppqqHwC4/T5mw=
github.com/spotinst/spotinst-sdk-go v1.58.0 h1:h7617CMlfHL3W+CMlhs883kVy3MPdGML/Z4+mW+ddgc=
github.com/spotinst/spotinst-sdk-go v1.58.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=

View File

@ -81,6 +81,7 @@ const (
// specific instance types.
InstanceGroupLabelOceanInstanceTypesWhitelist = "spotinst.io/ocean-instance-types-whitelist"
InstanceGroupLabelOceanInstanceTypesBlacklist = "spotinst.io/ocean-instance-types-blacklist"
InstanceGroupLabelOceanInstanceTypes = "spotinst.io/ocean-instance-types" // launchspec
// InstanceGroupLabelAutoScalerDisabled is the metadata label used on the
// instance group to specify whether the auto scaler should be enabled.
@ -509,6 +510,17 @@ func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
Ocean: ocean, // link to Ocean
}
// Instance types.
for k, v := range ig.ObjectMeta.Labels {
switch k {
case InstanceGroupLabelOceanInstanceTypesWhitelist, InstanceGroupLabelOceanInstanceTypes:
launchSpec.InstanceTypes, err = parseStringSlice(v)
if err != nil {
return err
}
}
}
// Capacity.
minSize, maxSize := b.buildCapacity(ig)
ocean.MinSize = fi.Int64(fi.Int64Value(ocean.MinSize) + fi.Int64Value(minSize))

View File

@ -45,6 +45,7 @@ type LaunchSpec struct {
Subnets []*awstasks.Subnet
IAMInstanceProfile *awstasks.IAMInstanceProfile
ImageID *string
InstanceTypes []string
Tags map[string]string
RootVolumeOpts *RootVolumeOpts
AutoScalerOpts *AutoScalerOpts
@ -207,6 +208,13 @@ func (o *LaunchSpec) Find(c *fi.Context) (*LaunchSpec, error) {
}
}
// Instance types.
{
if itypes := spec.InstanceTypes; itypes != nil {
actual.InstanceTypes = itypes
}
}
// Tags.
{
if len(spec.Tags) > 0 {
@ -376,6 +384,13 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
}
}
// Instance types.
{
if e.InstanceTypes != nil {
spec.SetInstanceTypes(e.InstanceTypes)
}
}
// Tags.
{
if e.Tags != nil {
@ -545,6 +560,15 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
}
}
// Instance types.
{
if changes.InstanceTypes != nil {
spec.SetInstanceTypes(e.InstanceTypes)
changes.InstanceTypes = nil
changed = true
}
}
// Tags.
{
if changes.Tags != nil {
@ -647,6 +671,7 @@ type terraformLaunchSpec struct {
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
IAMInstanceProfile *terraform.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
KeyName *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
InstanceTypes []string `json:"instance_types,omitempty" cty:"instance_types"`
SubnetIDs []*terraform.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty" cty:"security_groups"`
Taints []*corev1.Taint `json:"taints,omitempty" cty:"taints"`
@ -661,6 +686,7 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
tf := &terraformLaunchSpec{
Name: e.Name,
OceanID: e.Ocean.TerraformLink(),
InstanceTypes: e.InstanceTypes,
}
// Image.

View File

@ -356,6 +356,7 @@ type Route53Integration struct {
type Domain struct {
HostedZoneID *string `json:"hostedZoneId,omitempty"`
SpotinstAccountID *string `json:"spotinstAccountId,omitempty"`
RecordSetType *string `json:"recordSetType,omitempty"`
RecordSets []*RecordSet `json:"recordSets,omitempty"`
forceSendFields []string
@ -363,8 +364,9 @@ type Domain struct {
}
type RecordSet struct {
UsePublicIP *bool `json:"usePublicIp,omitempty"`
Name *string `json:"name,omitempty"`
UsePublicIP *bool `json:"usePublicIp,omitempty"`
UsePublicDNS *bool `json:"usePublicDns,omitempty"`
forceSendFields []string
nullFields []string
@ -2083,6 +2085,13 @@ func (o *Domain) SetSpotinstAccountID(v *string) *Domain {
return o
}
func (o *Domain) SetRecordSetType(v *string) *Domain {
if o.RecordSetType = v; o.RecordSetType == nil {
o.nullFields = append(o.nullFields, "RecordSetType")
}
return o
}
func (o *Domain) SetRecordSets(v []*RecordSet) *Domain {
if o.RecordSets = v; o.RecordSets == nil {
o.nullFields = append(o.nullFields, "RecordSets")
@ -2100,6 +2109,13 @@ func (o RecordSet) MarshalJSON() ([]byte, error) {
return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields)
}
func (o *RecordSet) SetName(v *string) *RecordSet {
if o.Name = v; o.Name == nil {
o.nullFields = append(o.nullFields, "Name")
}
return o
}
func (o *RecordSet) SetUsePublicIP(v *bool) *RecordSet {
if o.UsePublicIP = v; o.UsePublicIP == nil {
o.nullFields = append(o.nullFields, "UsePublicIP")
@ -2107,9 +2123,9 @@ func (o *RecordSet) SetUsePublicIP(v *bool) *RecordSet {
return o
}
func (o *RecordSet) SetName(v *string) *RecordSet {
if o.Name = v; o.Name == nil {
o.nullFields = append(o.nullFields, "Name")
func (o *RecordSet) SetUsePublicDNS(v *bool) *RecordSet {
if o.UsePublicDNS = v; o.UsePublicDNS == nil {
o.nullFields = append(o.nullFields, "UsePublicDNS")
}
return o
}

View File

@ -22,6 +22,7 @@ type LaunchSpec struct {
RootVolumeSize *int `json:"rootVolumeSize,omitempty"`
SecurityGroupIDs []string `json:"securityGroupIds,omitempty"`
SubnetIDs []string `json:"subnetIds,omitempty"`
InstanceTypes []string `json:"instanceTypes,omitempty"`
ResourceLimits *ResourceLimits `json:"resourceLimits,omitempty"`
IAMInstanceProfile *IAMInstanceProfile `json:"iamInstanceProfile,omitempty"`
AutoScale *AutoScale `json:"autoScale,omitempty"`
@ -397,6 +398,13 @@ func (o *LaunchSpec) SetSubnetIDs(v []string) *LaunchSpec {
return o
}
func (o *LaunchSpec) SetInstanceTypes(v []string) *LaunchSpec {
if o.InstanceTypes = v; o.InstanceTypes == nil {
o.nullFields = append(o.nullFields, "InstanceTypes")
}
return o
}
func (o *LaunchSpec) SetRootVolumeSize(v *int) *LaunchSpec {
if o.RootVolumeSize = v; o.RootVolumeSize == nil {
o.nullFields = append(o.nullFields, "RootVolumeSize")

View File

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

2
vendor/modules.txt vendored
View File

@ -516,7 +516,7 @@ github.com/spf13/pflag
# github.com/spf13/viper v1.4.0
## explicit
github.com/spf13/viper
# github.com/spotinst/spotinst-sdk-go v1.56.0
# github.com/spotinst/spotinst-sdk-go v1.58.0
## explicit
github.com/spotinst/spotinst-sdk-go/service/elastigroup
github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/aws