add Label Resource Tag Specification Volumes

This commit is contained in:
yehielnetapp 2023-11-09 12:05:57 +02:00
parent 1e6ec01eb3
commit 00fc4e78e8
3 changed files with 95 additions and 52 deletions

View File

@ -198,15 +198,16 @@ metadata:
labels: labels:
spotinst.io/strategy-cluster-spread-nodes-by: "count" spotinst.io/strategy-cluster-spread-nodes-by: "count"
spotinst.io/strategy-cluster-orientation-availability-vs-cost: "balanced" spotinst.io/strategy-cluster-orientation-availability-vs-cost: "balanced"
spotinst.io/resource-tag-specification-volumes: "true"
... ...
``` ```
| Label | Description | Default | || 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-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` | | `spotinst.io/strategy-cluster-orientation-availability-vs-cost` | Specify approach [cost,balanced,cheapest] that Ocean takes while launching nodes. | `balanced` |
| `spotinst.io/resource-tag-specification-volumes` | Specify if Volume resources will be tagged with Virtual Node Group tags or Ocean tags. | `false` |
## 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.

View File

@ -135,6 +135,10 @@ const (
// SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost is the metadata label used on the // SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost is the metadata label used on the
// instance group to specify how to optimize towards continuity and/or cost-effective infrastructure // instance group to specify how to optimize towards continuity and/or cost-effective infrastructure
SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost = "spotinst.io/strategy-cluster-orientation-availability-vs-cost" SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost = "spotinst.io/strategy-cluster-orientation-availability-vs-cost"
// SpotClusterLabelResourceTagSpecificationVolumes
// Specify if Volume resources will be tagged with Virtual Node Group tags or Ocean tags.
SpotClusterLabelResourceTagSpecificationVolumes = "spotinst.io/resource-tag-specification-volumes"
) )
// SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects // SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects
@ -387,6 +391,11 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont
ocean.SpreadNodesBy = fi.PtrTo(v) ocean.SpreadNodesBy = fi.PtrTo(v)
case SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost: case SpotClusterLabelStrategyClusterOrientationAvailabilityVsCost:
ocean.AvailabilityVsCost = fi.PtrTo(string(spotinsttasks.NormalizeClusterOrientation(&v))) ocean.AvailabilityVsCost = fi.PtrTo(string(spotinsttasks.NormalizeClusterOrientation(&v)))
case SpotClusterLabelResourceTagSpecificationVolumes:
ocean.ResourceTagSpecificationVolumes, err = parseBool(v)
if err != nil {
return err
}
} }
} }

View File

@ -66,6 +66,7 @@ type Ocean struct {
InstanceMetadataOptions *InstanceMetadataOptions InstanceMetadataOptions *InstanceMetadataOptions
SpreadNodesBy *string SpreadNodesBy *string
AvailabilityVsCost *string AvailabilityVsCost *string
ResourceTagSpecificationVolumes *bool
} }
var ( var (
@ -304,6 +305,11 @@ func (o *Ocean) Find(c *fi.CloudupContext) (*Ocean, error) {
actual.InstanceMetadataOptions.HTTPTokens = fi.PtrTo(fi.ValueOf(lc.InstanceMetadataOptions.HTTPTokens)) actual.InstanceMetadataOptions.HTTPTokens = fi.PtrTo(fi.ValueOf(lc.InstanceMetadataOptions.HTTPTokens))
actual.InstanceMetadataOptions.HTTPPutResponseHopLimit = fi.PtrTo(int64(fi.ValueOf(lc.InstanceMetadataOptions.HTTPPutResponseHopLimit))) actual.InstanceMetadataOptions.HTTPPutResponseHopLimit = fi.PtrTo(int64(fi.ValueOf(lc.InstanceMetadataOptions.HTTPPutResponseHopLimit)))
} }
//
if lc.ResourceTagSpecification != nil {
actual.ResourceTagSpecificationVolumes = fi.PtrTo(fi.ValueOf(lc.ResourceTagSpecification.Volumes.ShouldTag))
}
} }
// Auto Scaler. // Auto Scaler.
@ -483,6 +489,16 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
ocean.Compute.LaunchSpecification.SetInstanceMetadataOptions(opt) ocean.Compute.LaunchSpecification.SetInstanceMetadataOptions(opt)
} }
} }
//
{
if e.ResourceTagSpecificationVolumes != nil {
opt := new(aws.ResourceTagSpecification)
vol := new(aws.Volumes)
vol.SetShouldTag(fi.PtrTo(fi.ValueOf(e.ResourceTagSpecificationVolumes)))
opt.SetVolumes(vol)
ocean.Compute.LaunchSpecification.SetResourceTagSpecification(opt)
}
}
if !fi.ValueOf(e.UseAsTemplateOnly) { if !fi.ValueOf(e.UseAsTemplateOnly) {
// User data. // User data.
{ {
@ -830,7 +846,22 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
changed = true changed = true
} }
} }
// ResourceTagSpecificationVolumes.
{
if changes.ResourceTagSpecificationVolumes != nil {
if ocean.Compute == nil {
ocean.Compute = new(aws.Compute)
}
if ocean.Compute.LaunchSpecification == nil {
ocean.Compute.LaunchSpecification = new(aws.LaunchSpecification)
}
opt := new(aws.ResourceTagSpecification)
opt.Volumes.SetShouldTag(fi.PtrTo(fi.ValueOf(e.ResourceTagSpecificationVolumes)))
ocean.Compute.LaunchSpecification.SetResourceTagSpecification(opt)
changes.ResourceTagSpecificationVolumes = nil
changed = true
}
}
// Template. // Template.
{ {
if changes.UseAsTemplateOnly != nil { if changes.UseAsTemplateOnly != nil {
@ -1120,6 +1151,7 @@ type terraformOcean struct {
SecurityGroups []*terraformWriter.Literal `cty:"security_groups"` SecurityGroups []*terraformWriter.Literal `cty:"security_groups"`
SpreadNodesBy *string `cty:"spread_nodes_by"` SpreadNodesBy *string `cty:"spread_nodes_by"`
AvailabilityVsCost *string `cty:"availability_vs_cost"` AvailabilityVsCost *string `cty:"availability_vs_cost"`
ResourceTagSpecificationVolumes *bool `cty:"resource_tag_specification_volumes"`
} }
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error { func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
@ -1136,6 +1168,7 @@ func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Oce
GracePeriod: e.GracePeriod, GracePeriod: e.GracePeriod,
SpreadNodesBy: e.SpreadNodesBy, SpreadNodesBy: e.SpreadNodesBy,
AvailabilityVsCost: e.AvailabilityVsCost, AvailabilityVsCost: e.AvailabilityVsCost,
ResourceTagSpecificationVolumes: e.ResourceTagSpecificationVolumes,
} }
// Image. // Image.