Skip to content
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

feat: allow customizing spot allocation strategy #481

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vucong2409
Copy link

Allow user to pass Spot Allocation Strategy into Fleet Request.

Closes #427

@vucong2409 vucong2409 requested a review from a team as a code owner May 10, 2024 11:15
Copy link

hashicorp-cla-app bot commented May 10, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vucong2409,

Thanks for taking a jab at this!

I left a couple comments/suggestions regarding the formatting of the docs and validation of the option, please let me know if you need some help or more explanation, otherwise feel free to address this feedback and I'll do another round of review then.

Thanks again!

builder/common/run_config.go Outdated Show resolved Hide resolved
builder/common/step_run_spot_instance.go Outdated Show resolved Hide resolved
@vucong2409 vucong2409 force-pushed the feat/allow-custom-spot-allocation-strat branch 2 times, most recently from b12598c to b35667a Compare May 11, 2024 03:34
@vucong2409 vucong2409 force-pushed the feat/allow-custom-spot-allocation-strat branch from b35667a to 807b998 Compare May 11, 2024 03:35
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vucong2409,

Sorry I forgot to do another pass of review after you updated this, I've left another review on the code, this looks good however I'm not sure the option should be common if it is ebs-specific, please let me know if something's unclear in my comments, and I can try to clarify.

Otherwise I'll let you address those comments, and I'll be back later for another round of reviews.

Thanks!

@@ -251,6 +251,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SpotTags: b.config.SpotTags,
Tags: b.config.RunTags,
SpotInstanceTypes: b.config.SpotInstanceTypes,
SpotAllocationStrategy: b.config.RunConfig.SpotAllocationStrategy,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this setting should be replicated to other builders, assuming this is compatible with them.
Otherwise I would suggest either:

  1. moving that argument to builder/ebs/config.go so it is not common
  2. checking that it is not set in the configs for the builders that aren't compatible with it, this can be done in the Prepare function for each builder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if the ebs builder's the only one to support spot instances, I would suggest going with approach 1

@@ -843,6 +851,13 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
}
}

if c.SpotAllocationStrategy != "" {
if !slices.Contains(ec2.SpotAllocationStrategy_Values(), c.SpotAllocationStrategy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe both ifs can be mutualised

Suggested change
if !slices.Contains(ec2.SpotAllocationStrategy_Values(), c.SpotAllocationStrategy) {
if c.SpotAllocationStrategy != "" && !slices.Contains(ec2.SpotAllocationStrategy_Values(), c.SpotAllocationStrategy) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also to reply to your question in a comment from a previous review: using slices.Contains is fine by my standards! No need to make it manual, I suspect those were made this way in other cases because either the function did not exist at the time it was added, or whomever implemented it wasn't aware it existed, functionally it is essentially the same, might as well use what the library offers us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Customizing Spot Allocation Strategy
2 participants