-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spotinst: New hybrid integration mode #7252
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,18 @@ import ( | |
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/pkg/featureflag" | ||
"k8s.io/kops/pkg/model" | ||
"k8s.io/kops/pkg/model/awsmodel" | ||
"k8s.io/kops/pkg/model/defaults" | ||
"k8s.io/kops/upup/pkg/fi" | ||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks" | ||
"k8s.io/kops/upup/pkg/fi/cloudup/spotinsttasks" | ||
) | ||
|
||
const ( | ||
// InstanceGroupLabelHybrid is the metadata label used on the instance group | ||
// to specify that the Spotinst provider should be used to upon creation. | ||
InstanceGroupLabelHybrid = "spotinst.io/hybrid" | ||
InstanceGroupLabelManaged = "spotinst.io/managed" // for backward compatibility | ||
|
||
// InstanceGroupLabelSpotPercentage is the metadata label used on the | ||
// instance group to specify the percentage of Spot instances that | ||
// should spin up from the target capacity. | ||
|
@@ -101,7 +105,7 @@ const ( | |
|
||
// InstanceGroupModelBuilder configures InstanceGroup objects | ||
type InstanceGroupModelBuilder struct { | ||
*awsmodel.AWSModelContext | ||
*model.KopsModelContext | ||
|
||
BootstrapScript *model.BootstrapScript | ||
Lifecycle *fi.Lifecycle | ||
|
@@ -115,8 +119,16 @@ func (b *InstanceGroupModelBuilder) Build(c *fi.ModelBuilderContext) error { | |
var err error | ||
|
||
for _, ig := range b.InstanceGroups { | ||
klog.V(2).Infof("Building instance group: %q", b.AutoscalingGroupName(ig)) | ||
name := b.AutoscalingGroupName(ig) | ||
|
||
if featureflag.SpotinstHybrid.Enabled() { | ||
if !HybridInstanceGroup(ig) { | ||
klog.V(2).Infof("Skipping instance group: %q", name) | ||
continue | ||
} | ||
} | ||
|
||
klog.V(2).Infof("Building instance group: %q", name) | ||
switch ig.Spec.Role { | ||
|
||
// Create both Master and Bastion instance groups as Elastigroups. | ||
|
@@ -642,7 +654,7 @@ func (b *InstanceGroupModelBuilder) buildRootVolumeOpts(ig *kops.InstanceGroup) | |
{ | ||
typ := fi.StringValue(ig.Spec.RootVolumeType) | ||
if typ == "" { | ||
typ = awsmodel.DefaultVolumeType | ||
typ = "gp2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no other compatibility within spotinst? Hardcoding defaults looks weird to me - why is this an option to set then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just follow the AWS implementation, but have to replace the use of the const Do you think we should implement it differently? If so, I'd change it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this is just about cyclic imports, I see. Thanks! |
||
} | ||
opts.Type = fi.String(typ) | ||
} | ||
|
@@ -913,3 +925,16 @@ func defaultSpotPercentage(ig *kops.InstanceGroup) *float64 { | |
|
||
return &percentage | ||
} | ||
|
||
// HybridInstanceGroup indicates whether the instance group labeled with | ||
// a metadata label `spotinst.io/hybrid` which means the Spotinst provider | ||
// should be used to upon creation if the `SpotinstHybrid` feature flag is on. | ||
func HybridInstanceGroup(ig *kops.InstanceGroup) bool { | ||
v, ok := ig.ObjectMeta.Labels[InstanceGroupLabelHybrid] | ||
if !ok { | ||
v = ig.ObjectMeta.Labels[InstanceGroupLabelManaged] | ||
} | ||
|
||
hybrid, _ := strconv.ParseBool(v) | ||
return hybrid | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean when I activate this feature flag I just override the use of AutoScaling Groups?
I am not a big fan of changing behaviour with feature flags. As the name suggests, it should add features, not modify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not. It just means that you'd like to use Spotinst for one or more instance groups. It allows users to continue managing their instance groups through AWS Auto Scaling groups, except for specific ones labeled with our metadata label (
spotinst.io/hybrid: "true"
). So, if you toggle the feature flag on but without setting the metadata label you do not override anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thank you for clarifying!