Skip to content

Commit 7c17b16

Browse files
authored
Merge pull request #16099 from spotinst/feat/add_multi_arch_base127_rebase
Spotinst: Feature/add multi arch in VNG and resource tag specification
2 parents 634423f + 30813fe commit 7c17b16

File tree

23 files changed

+2437
-141
lines changed

23 files changed

+2437
-141
lines changed

docs/getting_started/spot-ocean.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,31 @@ metadata:
161161
162162
| Label | Description | Default |
163163
|---|---|---|
164-
| `spotinst.io/spot-percentage` | Specify the percentage of Spot instances that should spin up from the target capacity. | `100` |
165-
| `spotinst.io/utilize-reserved-instances` | Specify whether reserved instances should be utilized. | `true` |
166-
| `spotinst.io/utilize-commitments` | Specify whether reserved instance commitments should be utilized. | none |
167-
| `spotinst.io/fallback-to-ondemand` | Specify whether fallback to on-demand instances should be enabled. | `true` |
164+
| `spotinst.io/spot-percentage` | Specify the percentage of Spot instances that should spin up from the target capacity. | `100` |
165+
| `spotinst.io/utilize-reserved-instances` | Specify whether reserved instances should be utilized. | `true` |
166+
| `spotinst.io/utilize-commitments` | Specify whether reserved instance commitments should be utilized. | none |
167+
| `spotinst.io/fallback-to-ondemand` | Specify whether fallback to on-demand instances should be enabled. | `true` |
168168
| `spotinst.io/draining-timeout` | Specify a period of time, in seconds, after a node is marked for termination during which on running pods remains active. | none |
169-
| `spotinst.io/grace-period` | Specify a period of time, in seconds, that Ocean should wait before applying instance health checks. | none |
170-
| `spotinst.io/ocean-default-launchspec` | Specify whether to use the InstanceGroup's spec as the default Launch Spec for the Ocean cluster. | none |
171-
| `spotinst.io/ocean-instance-types-whitelist` | Specify whether to whitelist specific instance types. | none |
172-
| `spotinst.io/ocean-instance-types-blacklist` | Specify whether to blacklist specific instance types. | none |
173-
| `spotinst.io/ocean-instance-types` | Specify a list of instance types that should be used by the Ocean Launch Spec. | none |
174-
| `spotinst.io/autoscaler-disabled` | Specify whether the auto scaler should be disabled. | `false` |
175-
| `spotinst.io/autoscaler-default-node-labels` | Specify whether default node labels should be set for the auto scaler. | `false` |
176-
| `spotinst.io/autoscaler-auto-config` | Specify whether headroom resources should be automatically configured and optimized. | `true` |
177-
| `spotinst.io/autoscaler-auto-headroom-percentage` | Specify the auto headroom percentage (a number in the range [0, 200]) which controls the percentage of headroom. | none |
178-
| `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 |
179-
| `spotinst.io/autoscaler-headroom-gpu-per-unit` | Specify the number of GPUs to allocate for headroom. | none |
180-
| `spotinst.io/autoscaler-headroom-mem-per-unit` | Specify the amount of memory (MB) to allocate for headroom. | none |
181-
| `spotinst.io/autoscaler-headroom-num-of-units` | Specify the number of units to retain as headroom, where each unit has the defined CPU and memory. | none |
182-
| `spotinst.io/autoscaler-cooldown` | Specify a period of time, in seconds, that Ocean should wait between scaling actions. | `300` |
183-
| `spotinst.io/autoscaler-scale-down-max-percentage` | Specify the maximum scale down percentage. | none |
184-
| `spotinst.io/autoscaler-scale-down-evaluation-periods` | Specify the number of evaluation periods that should accumulate before a scale down action takes place. | `5` |
185-
| `spotinst.io/autoscaler-resource-limits-max-vcpu` | Specify the maximum number of virtual CPUs that can be allocated to the cluster. | none |
186-
| `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 |
187-
| `spotinst.io/restrict-scale-down` | Specify whether the scale-down activities should be restricted. | none |
169+
| `spotinst.io/grace-period` | Specify a period of time, in seconds, that Ocean should wait before applying instance health checks. | none |
170+
| `spotinst.io/ocean-default-launchspec` | Specify whether to use the InstanceGroup's spec as the default Launch Spec for the Ocean cluster. | none |
171+
| `spotinst.io/ocean-instance-types-whitelist` | Specify whether to whitelist specific instance types. | none |
172+
| `spotinst.io/ocean-instance-types-blacklist` | Specify whether to blacklist specific instance types. | none |
173+
| `spotinst.io/ocean-instance-types` | Specify a list of instance types that should be used by the Ocean Launch Spec. | none |
174+
| `spotinst.io/autoscaler-disabled` | Specify whether the auto scaler should be disabled. | `false` |
175+
| `spotinst.io/autoscaler-default-node-labels` | Specify whether default node labels should be set for the auto scaler. | `false` |
176+
| `spotinst.io/autoscaler-auto-config` | Specify whether headroom resources should be automatically configured and optimized. | `true` |
177+
| `spotinst.io/autoscaler-auto-headroom-percentage` | Specify the auto headroom percentage (a number in the range [0, 200]) which controls the percentage of headroom. | none |
178+
| `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 |
179+
| `spotinst.io/autoscaler-headroom-gpu-per-unit` | Specify the number of GPUs to allocate for headroom. | none |
180+
| `spotinst.io/autoscaler-headroom-mem-per-unit` | Specify the amount of memory (MB) to allocate for headroom. | none |
181+
| `spotinst.io/autoscaler-headroom-num-of-units` | Specify the number of units to retain as headroom, where each unit has the defined CPU and memory. | none |
182+
| `spotinst.io/autoscaler-cooldown` | Specify a period of time, in seconds, that Ocean should wait between scaling actions. | `300` |
183+
| `spotinst.io/autoscaler-scale-down-max-percentage` | Specify the maximum scale down percentage. | none |
184+
| `spotinst.io/autoscaler-scale-down-evaluation-periods` | Specify the number of evaluation periods that should accumulate before a scale down action takes place. | `5` |
185+
| `spotinst.io/autoscaler-resource-limits-max-vcpu` | Specify the maximum number of virtual CPUs that can be allocated to the cluster. | none |
186+
| `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 |
187+
| `spotinst.io/restrict-scale-down` | Specify whether the scale-down activities should be restricted. | none |
188+
| `spotinst.io/other-architecture-images` | Specify other architecture images. | none |
188189

189190
## Cluster Metadata Labels
190191
```yaml
@@ -198,15 +199,16 @@ metadata:
198199
labels:
199200
spotinst.io/strategy-cluster-spread-nodes-by: "count"
200201
spotinst.io/strategy-cluster-orientation-availability-vs-cost: "balanced"
202+
spotinst.io/resource-tag-specification-volumes: "true"
201203
...
202204
```
203205

204206

205-
| Label | Description | Default |
206-
|---|---|---|
207-
| `spotinst.io/strategy-cluster-spread-nodes-by` | Specify how Ocean will spread the nodes across markets by this value [vcpu,count]. | `count` |
208-
| `spotinst.io/strategy-cluster-orientation-availability-vs-cost` | Specify approach [cost,balanced,cheapest] that Ocean takes while launching nodes. | `balanced` |
209-
207+
|| Label | Description | Default |
208+
|---|----------------------------------------------------------------------------------------|---|
209+
| `spotinst.io/strategy-cluster-spread-nodes-by` | Specify how Ocean will spread the nodes across markets by this value [vcpu,count]. | `count` |
210+
| `spotinst.io/strategy-cluster-orientation-availability-vs-cost` | Specify approach [cost,balanced,cheapest] that Ocean takes while launching nodes. | `balanced` |
211+
| `spotinst.io/resource-tag-specification-volumes` | Specify if Volume resources will be tagged with Virtual Node Group tags or Ocean tags. | `false` |
210212
## Documentation
211213

212214
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.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/spf13/cobra v1.8.0
3939
github.com/spf13/pflag v1.0.5
4040
github.com/spf13/viper v1.17.0
41-
github.com/spotinst/spotinst-sdk-go v1.145.0
41+
github.com/spotinst/spotinst-sdk-go v1.171.0
4242
github.com/stretchr/testify v1.8.4
4343
github.com/weaveworks/mesh v0.0.0-20191105120815-58dbcc3e8e63
4444
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
685685
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
686686
github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI=
687687
github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI=
688-
github.com/spotinst/spotinst-sdk-go v1.145.0 h1:c/PufzKMbjmqSYcVHr+TuNpcZ6x5+jZALVGTesbJ7q4=
689-
github.com/spotinst/spotinst-sdk-go v1.145.0/go.mod h1:Ku9c4p+kRWnQqmXkzGcTMHLcQKgLHrQZISxeKY7mPqE=
688+
github.com/spotinst/spotinst-sdk-go v1.171.0 h1:ZihMPEjkpIkSpawWLJt9RtCRY4mOQMGlfrkVmA03000=
689+
github.com/spotinst/spotinst-sdk-go v1.171.0/go.mod h1:Ku9c4p+kRWnQqmXkzGcTMHLcQKgLHrQZISxeKY7mPqE=
690690
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
691691
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
692692
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=

pkg/model/awsmodel/spotinst.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ const (
114114
// instance group to specify the cooldown period (in seconds) for scaling actions.
115115
SpotInstanceGroupLabelAutoScalerCooldown = "spotinst.io/autoscaler-cooldown"
116116

117+
// SpotInstanceGroupLabelOtherArchitectureImages Identifier of other architecture image in AWS.
118+
//For each architecture type (amd64, arm64) only one AMI is allowed,first image is from config.InstanceGroup.spec.image
119+
SpotInstanceGroupLabelOtherArchitectureImages = "spotinst.io/other-architecture-images"
120+
117121
// SpotInstanceGroupLabelAutoScalerScaleDown* are the metadata labels used on the
118122
// instance group to specify the scale down configuration used by the auto scaler.
119123
SpotInstanceGroupLabelAutoScalerScaleDownMaxPercentage = "spotinst.io/autoscaler-scale-down-max-percentage"
@@ -135,6 +139,10 @@ const (
135139
// SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost is the metadata label used on the
136140
// instance group to specify how to optimize towards continuity and/or cost-effective infrastructure
137141
SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost = "spotinst.io/strategy-cluster-orientation-availability-vs-cost"
142+
143+
// SpotClusterLabelResourceTagSpecificationVolumes
144+
// Specify if Volume resources will be tagged with Virtual Node Group tags or Ocean tags.
145+
SpotClusterLabelResourceTagSpecificationVolumes = "spotinst.io/resource-tag-specification-volumes"
138146
)
139147

140148
// SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects
@@ -387,6 +395,11 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont
387395
ocean.SpreadNodesBy = fi.PtrTo(v)
388396
case SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost:
389397
ocean.AvailabilityVsCost = fi.PtrTo(string(spotinsttasks.NormalizeClusterOrientation(&v)))
398+
case SpotClusterLabelResourceTagSpecificationVolumes:
399+
ocean.ResourceTagSpecificationVolumes, err = parseBool(v)
400+
if err != nil {
401+
return err
402+
}
390403
}
391404
}
392405

@@ -524,7 +537,7 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont
524537

525538
klog.V(4).Infof("Adding task: Ocean/%s", fi.ValueOf(ocean.Name))
526539
c.AddTask(ocean)
527-
540+
klog.V(4).Infof("Finish task: Ocean/%s", fi.ValueOf(ocean.Name))
528541
return nil
529542
}
530543

@@ -558,6 +571,12 @@ func (b *SpotInstanceGroupModelBuilder) buildLaunchSpec(c *fi.CloudupModelBuilde
558571
if err != nil {
559572
return err
560573
}
574+
575+
case SpotInstanceGroupLabelOtherArchitectureImages:
576+
launchSpec.OtherArchitectureImages, err = parseStringSlice(v)
577+
if err != nil {
578+
return err
579+
}
561580
}
562581
}
563582

upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type LaunchSpec struct {
5555
MinSize *int64
5656
MaxSize *int64
5757
InstanceMetadataOptions *InstanceMetadataOptions
58+
OtherArchitectureImages []string
5859

5960
Ocean *Ocean
6061
}
@@ -157,8 +158,12 @@ func (o *LaunchSpec) Find(c *fi.CloudupContext) (*LaunchSpec, error) {
157158

158159
// Image.
159160
{
161+
// convert spec from api that reply for multi arch data only in spec.images
162+
if spec.Images != nil && len(spec.Images) > 1 {
163+
spec.SetImageId(fi.PtrTo(fi.ValueOf(spec.Images[0].ImageId)))
164+
actual.OtherArchitectureImages = append(actual.OtherArchitectureImages, fi.ValueOf(spec.Images[1].ImageId))
165+
}
160166
actual.ImageID = spec.ImageID
161-
162167
if o.ImageID != nil && actual.ImageID != nil &&
163168
fi.ValueOf(actual.ImageID) != fi.ValueOf(o.ImageID) {
164169
image, err := resolveImage(cloud, fi.ValueOf(o.ImageID))
@@ -169,6 +174,16 @@ func (o *LaunchSpec) Find(c *fi.CloudupContext) (*LaunchSpec, error) {
169174
actual.ImageID = o.ImageID
170175
}
171176
}
177+
if o.OtherArchitectureImages != nil && actual.OtherArchitectureImages != nil &&
178+
(actual.OtherArchitectureImages[0] != o.OtherArchitectureImages[0]) {
179+
image, err := resolveImage(cloud, o.OtherArchitectureImages[0])
180+
if err != nil {
181+
return nil, err
182+
}
183+
if fi.ValueOf(image.ImageId) == actual.OtherArchitectureImages[0] {
184+
actual.OtherArchitectureImages[0] = o.OtherArchitectureImages[0]
185+
}
186+
}
172187
}
173188

174189
// User data.
@@ -395,12 +410,21 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
395410

396411
// Image.
397412
{
398-
if e.ImageID != nil {
413+
if e.ImageID != nil && len(e.OtherArchitectureImages) == 0 { //old api
399414
image, err := resolveImage(cloud, fi.ValueOf(e.ImageID))
400415
if err != nil {
401416
return err
402417
}
403418
spec.SetImageId(image.ImageId)
419+
} else {
420+
if e.ImageID != nil && len(e.OtherArchitectureImages) == 1 {
421+
images, err := buildImages(cloud, e.ImageID, e.OtherArchitectureImages)
422+
if err != nil {
423+
return err
424+
}
425+
spec.SetImageId(nil)
426+
spec.SetImages(images)
427+
}
404428
}
405429
}
406430

@@ -610,7 +634,7 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
610634

611635
// Image.
612636
{
613-
if changes.ImageID != nil {
637+
if changes.ImageID != nil { //old api
614638
image, err := resolveImage(cloud, fi.ValueOf(e.ImageID))
615639
if err != nil {
616640
return err
@@ -619,10 +643,21 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
619643
if fi.ValueOf(actual.ImageID) != fi.ValueOf(image.ImageId) {
620644
spec.SetImageId(image.ImageId)
621645
}
622-
623646
changes.ImageID = nil
624647
changed = true
625648
}
649+
if changes.OtherArchitectureImages != nil {
650+
images, err := buildImages(cloud, spec.ImageID, e.OtherArchitectureImages)
651+
if err != nil {
652+
return err
653+
}
654+
spec.SetImageId(nil)
655+
spec.SetImages(images)
656+
changes.OtherArchitectureImages = nil
657+
changed = true
658+
659+
}
660+
626661
}
627662

628663
// User data.
@@ -1139,3 +1174,26 @@ func (o *LaunchSpec) convertBlockDeviceMapping(in *awstasks.BlockDeviceMapping)
11391174

11401175
return out
11411176
}
1177+
func buildImages(cloud awsup.AWSCloud, ImageID *string, OtherArchitectureImages []string) ([]*aws.Images, error) {
1178+
var imagesSlice []*aws.Images
1179+
var imageIndex = 0
1180+
if ImageID != nil {
1181+
image, err := resolveImage(cloud, fi.ValueOf(ImageID))
1182+
if err != nil {
1183+
return nil, err
1184+
}
1185+
imagesSlice = append(imagesSlice, &aws.Images{})
1186+
imagesSlice[imageIndex].SetImageId(image.ImageId)
1187+
imageIndex++
1188+
}
1189+
if len(OtherArchitectureImages) == 1 {
1190+
image2, err := resolveImage(cloud, OtherArchitectureImages[0])
1191+
if err != nil {
1192+
return nil, err
1193+
}
1194+
imagesSlice = append(imagesSlice, &aws.Images{})
1195+
imagesSlice[imageIndex].SetImageId(image2.ImageId)
1196+
}
1197+
1198+
return imagesSlice, nil
1199+
}

0 commit comments

Comments
 (0)