mirror of https://github.com/kubernetes/kops.git
Merge pull request #15424 from spotinst/feature/add_spreadNodesBy
Spotinst: add feature spread nodes by count/vcpu to markets
This commit is contained in:
commit
c5ad898ef9
|
|
@ -146,7 +146,7 @@ metadata:
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Metadata Labels
|
## InstanceGroup Metadata Labels
|
||||||
|
|
||||||
| Label | Description | Default |
|
| Label | Description | Default |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
|
@ -175,6 +175,27 @@ metadata:
|
||||||
| `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/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 |
|
| `spotinst.io/restrict-scale-down` | Specify whether the scale-down activities should be restricted. | none |
|
||||||
|
|
||||||
|
## Cluster Metadata Labels
|
||||||
|
```yaml
|
||||||
|
# cluster.yaml
|
||||||
|
# A Cluster with Ocean configuration.
|
||||||
|
---
|
||||||
|
apiVersion: kops.k8s.io/v1alpha2
|
||||||
|
kind: Cluster
|
||||||
|
metadata:
|
||||||
|
name: "example"
|
||||||
|
labels:
|
||||||
|
spotinst.io/strategy-cluster-spread-nodes-by: "count"
|
||||||
|
spotinst.io/strategy-cluster-orientation-availability-vs-cost: "balanced"
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
| Label | Description | Default |
|
||||||
|
|---|---|---|
|
||||||
|
| `spotinst.io/strategy-cluster-spread-nodes-by` | Specify how Ocean will spread the nodes across markets by this value [vcpu,count]. | `count` |
|
||||||
|
| `spotinst.io/strategy-cluster-orientation-availability-vs-cost` | Specify approach [cost,balanced,cheapest] that Ocean takes while launching nodes. | `balanced` |
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
If you're new to [Spot](https://spot.io/) and want to get started, please checkout our [Getting Started](https://docs.spot.io/connect-your-cloud-provider/) guide, available on the [Spot Documentation](https://docs.spot.io/) website.
|
If you're new to [Spot](https://spot.io/) and want to get started, please checkout our [Getting Started](https://docs.spot.io/connect-your-cloud-provider/) guide, available on the [Spot Documentation](https://docs.spot.io/) website.
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,14 @@ const (
|
||||||
// InstanceGroupLabelRestrictScaleDown is the metadata label used on the
|
// InstanceGroupLabelRestrictScaleDown is the metadata label used on the
|
||||||
// instance group to specify whether the scale-down activities should be restricted.
|
// instance group to specify whether the scale-down activities should be restricted.
|
||||||
SpotInstanceGroupLabelRestrictScaleDown = "spotinst.io/restrict-scale-down"
|
SpotInstanceGroupLabelRestrictScaleDown = "spotinst.io/restrict-scale-down"
|
||||||
|
|
||||||
|
// SpotClusterLabelSpreadNodesBy is the cloud label used on the
|
||||||
|
// cluster spec to specify how Ocean will spread the nodes across markets by this value
|
||||||
|
SpotClusterLabelSpreadNodesBy = "spotinst.io/strategy-cluster-spread-nodes-by"
|
||||||
|
|
||||||
|
// SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost is the metadata label used on the
|
||||||
|
// instance group to specify how to optimize towards continuity and/or cost-effective infrastructure
|
||||||
|
SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost = "spotinst.io/strategy-cluster-orientation-availability-vs-cost"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects
|
// SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects
|
||||||
|
|
@ -373,6 +381,15 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont
|
||||||
|
|
||||||
klog.V(4).Infof("Detected default launch spec: %q", b.AutoscalingGroupName(ig))
|
klog.V(4).Infof("Detected default launch spec: %q", b.AutoscalingGroupName(ig))
|
||||||
|
|
||||||
|
for k, v := range b.Cluster.Labels {
|
||||||
|
switch k {
|
||||||
|
case SpotClusterLabelSpreadNodesBy:
|
||||||
|
ocean.SpreadNodesBy = fi.PtrTo(v)
|
||||||
|
case SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost:
|
||||||
|
ocean.AvailabilityVsCost = fi.PtrTo(string(spotinsttasks.NormalizeClusterOrientation(&v)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Image.
|
// Image.
|
||||||
ocean.ImageID = fi.PtrTo(ig.Spec.Image)
|
ocean.ImageID = fi.PtrTo(ig.Spec.Image)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ type Ocean struct {
|
||||||
RootVolumeOpts *RootVolumeOpts
|
RootVolumeOpts *RootVolumeOpts
|
||||||
AutoScalerOpts *AutoScalerOpts
|
AutoScalerOpts *AutoScalerOpts
|
||||||
InstanceMetadataOptions *InstanceMetadataOptions
|
InstanceMetadataOptions *InstanceMetadataOptions
|
||||||
|
SpreadNodesBy *string
|
||||||
|
AvailabilityVsCost *string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -164,6 +166,10 @@ func (o *Ocean) Find(c *fi.CloudupContext) (*Ocean, error) {
|
||||||
if strategy.GracePeriod != nil {
|
if strategy.GracePeriod != nil {
|
||||||
actual.GracePeriod = fi.PtrTo(int64(fi.ValueOf(strategy.GracePeriod)))
|
actual.GracePeriod = fi.PtrTo(int64(fi.ValueOf(strategy.GracePeriod)))
|
||||||
}
|
}
|
||||||
|
actual.SpreadNodesBy = strategy.SpreadNodesBy
|
||||||
|
if strategy.ClusterOrientation != nil && strategy.ClusterOrientation.AvailabilityVsCost != nil {
|
||||||
|
actual.AvailabilityVsCost = fi.PtrTo(fi.ValueOf(strategy.ClusterOrientation.AvailabilityVsCost))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -402,6 +408,11 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
|
||||||
if e.GracePeriod != nil {
|
if e.GracePeriod != nil {
|
||||||
ocean.Strategy.SetGracePeriod(fi.PtrTo(int(*e.GracePeriod)))
|
ocean.Strategy.SetGracePeriod(fi.PtrTo(int(*e.GracePeriod)))
|
||||||
}
|
}
|
||||||
|
ocean.Strategy.SetSpreadNodesBy(e.SpreadNodesBy)
|
||||||
|
if e.AvailabilityVsCost != nil {
|
||||||
|
orientation := new(aws.ClusterOrientation)
|
||||||
|
ocean.Strategy.SetClusterOrientation(orientation.SetAvailabilityVsCost(fi.PtrTo(*e.AvailabilityVsCost)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute.
|
// Compute.
|
||||||
|
|
@ -677,6 +688,29 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
|
||||||
changes.GracePeriod = nil
|
changes.GracePeriod = nil
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Spread nodes by.
|
||||||
|
if changes.SpreadNodesBy != nil {
|
||||||
|
if ocean.Strategy == nil {
|
||||||
|
ocean.Strategy = new(aws.Strategy)
|
||||||
|
}
|
||||||
|
ocean.Strategy.SetSpreadNodesBy(e.SpreadNodesBy)
|
||||||
|
changes.SpreadNodesBy = nil
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Availability vs cost.
|
||||||
|
if changes.AvailabilityVsCost != nil {
|
||||||
|
if ocean.Strategy == nil {
|
||||||
|
ocean.Strategy = new(aws.Strategy)
|
||||||
|
}
|
||||||
|
|
||||||
|
orientation := new(aws.ClusterOrientation)
|
||||||
|
ocean.Strategy.SetClusterOrientation(orientation.SetAvailabilityVsCost(fi.PtrTo(*changes.AvailabilityVsCost)))
|
||||||
|
changes.AvailabilityVsCost = nil
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute.
|
// Compute.
|
||||||
|
|
@ -1084,6 +1118,8 @@ type terraformOcean struct {
|
||||||
IAMInstanceProfile *terraformWriter.Literal `cty:"iam_instance_profile"`
|
IAMInstanceProfile *terraformWriter.Literal `cty:"iam_instance_profile"`
|
||||||
KeyName *terraformWriter.Literal `cty:"key_name"`
|
KeyName *terraformWriter.Literal `cty:"key_name"`
|
||||||
SecurityGroups []*terraformWriter.Literal `cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `cty:"security_groups"`
|
||||||
|
SpreadNodesBy *string `cty:"spread_nodes_by"`
|
||||||
|
AvailabilityVsCost *string `cty:"availability_vs_cost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
|
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
|
||||||
|
|
@ -1098,6 +1134,8 @@ func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Oce
|
||||||
UtilizeCommitments: e.UtilizeCommitments,
|
UtilizeCommitments: e.UtilizeCommitments,
|
||||||
DrainingTimeout: e.DrainingTimeout,
|
DrainingTimeout: e.DrainingTimeout,
|
||||||
GracePeriod: e.GracePeriod,
|
GracePeriod: e.GracePeriod,
|
||||||
|
SpreadNodesBy: e.SpreadNodesBy,
|
||||||
|
AvailabilityVsCost: e.AvailabilityVsCost,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image.
|
// Image.
|
||||||
|
|
@ -1271,3 +1309,28 @@ func (o *Ocean) buildTags() []*aws.Tag {
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClusterOrientation string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ClusterOrientationBalanced ClusterOrientation = "balanced"
|
||||||
|
ClusterOrientationCheapest ClusterOrientation = "cheapest"
|
||||||
|
ClusterOrientationCost ClusterOrientation = "costOriented"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NormalizeClusterOrientation(orientation *string) ClusterOrientation {
|
||||||
|
out := ClusterOrientationBalanced
|
||||||
|
|
||||||
|
if orientation == nil {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
switch *orientation {
|
||||||
|
case "cost":
|
||||||
|
out = ClusterOrientationCost
|
||||||
|
case "cheapest":
|
||||||
|
out = ClusterOrientationCheapest
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue