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

@ -42,30 +42,31 @@ type Ocean struct {
Name *string Name *string
Lifecycle fi.Lifecycle Lifecycle fi.Lifecycle
MinSize *int64 MinSize *int64
MaxSize *int64 MaxSize *int64
UtilizeReservedInstances *bool UtilizeReservedInstances *bool
UtilizeCommitments *bool UtilizeCommitments *bool
FallbackToOnDemand *bool FallbackToOnDemand *bool
DrainingTimeout *int64 DrainingTimeout *int64
GracePeriod *int64 GracePeriod *int64
InstanceTypesWhitelist []string InstanceTypesWhitelist []string
InstanceTypesBlacklist []string InstanceTypesBlacklist []string
Tags map[string]string Tags map[string]string
UserData fi.Resource UserData fi.Resource
ImageID *string ImageID *string
IAMInstanceProfile *awstasks.IAMInstanceProfile IAMInstanceProfile *awstasks.IAMInstanceProfile
SSHKey *awstasks.SSHKey SSHKey *awstasks.SSHKey
Subnets []*awstasks.Subnet Subnets []*awstasks.Subnet
SecurityGroups []*awstasks.SecurityGroup SecurityGroups []*awstasks.SecurityGroup
Monitoring *bool Monitoring *bool
AssociatePublicIPAddress *bool AssociatePublicIPAddress *bool
UseAsTemplateOnly *bool UseAsTemplateOnly *bool
RootVolumeOpts *RootVolumeOpts RootVolumeOpts *RootVolumeOpts
AutoScalerOpts *AutoScalerOpts AutoScalerOpts *AutoScalerOpts
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 {
@ -1108,34 +1139,36 @@ type terraformOcean struct {
DrainingTimeout *int64 `cty:"draining_timeout"` DrainingTimeout *int64 `cty:"draining_timeout"`
GracePeriod *int64 `cty:"grace_period"` GracePeriod *int64 `cty:"grace_period"`
UseAsTemplateOnly *bool `cty:"use_as_template_only"` UseAsTemplateOnly *bool `cty:"use_as_template_only"`
Monitoring *bool `cty:"monitoring"` Monitoring *bool `cty:"monitoring"`
EBSOptimized *bool `cty:"ebs_optimized"` EBSOptimized *bool `cty:"ebs_optimized"`
ImageID *string `cty:"image_id"` ImageID *string `cty:"image_id"`
AssociatePublicIPAddress *bool `cty:"associate_public_ip_address"` AssociatePublicIPAddress *bool `cty:"associate_public_ip_address"`
RootVolumeSize *int64 `cty:"root_volume_size"` RootVolumeSize *int64 `cty:"root_volume_size"`
UserData *terraformWriter.Literal `cty:"user_data"` UserData *terraformWriter.Literal `cty:"user_data"`
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"` 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 {
cloud := t.Cloud.(awsup.AWSCloud) cloud := t.Cloud.(awsup.AWSCloud)
tf := &terraformOcean{ tf := &terraformOcean{
Name: e.Name, Name: e.Name,
Region: fi.PtrTo(cloud.Region()), Region: fi.PtrTo(cloud.Region()),
UseAsTemplateOnly: e.UseAsTemplateOnly, UseAsTemplateOnly: e.UseAsTemplateOnly,
FallbackToOnDemand: e.FallbackToOnDemand, FallbackToOnDemand: e.FallbackToOnDemand,
UtilizeReservedInstances: e.UtilizeReservedInstances, UtilizeReservedInstances: e.UtilizeReservedInstances,
UtilizeCommitments: e.UtilizeCommitments, UtilizeCommitments: e.UtilizeCommitments,
DrainingTimeout: e.DrainingTimeout, DrainingTimeout: e.DrainingTimeout,
GracePeriod: e.GracePeriod, GracePeriod: e.GracePeriod,
SpreadNodesBy: e.SpreadNodesBy, SpreadNodesBy: e.SpreadNodesBy,
AvailabilityVsCost: e.AvailabilityVsCost, AvailabilityVsCost: e.AvailabilityVsCost,
ResourceTagSpecificationVolumes: e.ResourceTagSpecificationVolumes,
} }
// Image. // Image.