Skip to content

Commit

Permalink
reformat docs and cover test
Browse files Browse the repository at this point in the history
  • Loading branch information
vucong2409 committed May 11, 2024
1 parent 807b998 commit e2ed97d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .web-docs/components/builder/ebs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,10 @@ JSON example:
filter, but will cause Packer to fail if the `source_ami` does not exist.

- `spot_allocation_strategy` (string) - One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)

- `spot_instance_types` ([]string) - a list of acceptable instance
types to run your build on. We will request a spot instance using the max
Expand Down
8 changes: 4 additions & 4 deletions .web-docs/components/builder/ebssurrogate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,10 @@ JSON example:
filter, but will cause Packer to fail if the `source_ami` does not exist.

- `spot_allocation_strategy` (string) - One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)

- `spot_instance_types` ([]string) - a list of acceptable instance
types to run your build on. We will request a spot instance using the max
Expand Down
8 changes: 4 additions & 4 deletions .web-docs/components/builder/ebsvolume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,10 @@ https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concept
filter, but will cause Packer to fail if the `source_ami` does not exist.

- `spot_allocation_strategy` (string) - One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)

- `spot_instance_types` ([]string) - a list of acceptable instance
types to run your build on. We will request a spot instance using the max
Expand Down
8 changes: 4 additions & 4 deletions .web-docs/components/builder/instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,10 @@ JSON example:
filter, but will cause Packer to fail if the `source_ami` does not exist.

- `spot_allocation_strategy` (string) - One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)

- `spot_instance_types` ([]string) - a list of acceptable instance
types to run your build on. We will request a spot instance using the max
Expand Down
8 changes: 4 additions & 4 deletions builder/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ type RunConfig struct {
// filter, but will cause Packer to fail if the `source_ami` does not exist.
SourceAmiFilter AmiFilterOptions `mapstructure:"source_ami_filter" required:"false"`
// One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
// The strategy that determines how to allocate the target Spot Instance capacity
// across the Spot Instance pools specified by the EC2 Fleet launch configuration.
// If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
// For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
// The strategy that determines how to allocate the target Spot Instance capacity
// across the Spot Instance pools specified by the EC2 Fleet launch configuration.
// If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
// For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
SpotAllocationStrategy string `mapstructure:"spot_allocation_strategy" required:"false"`
// a list of acceptable instance
// types to run your build on. We will request a spot instance using the max
Expand Down
10 changes: 10 additions & 0 deletions builder/common/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,13 @@ func TestRunConfigPrepare_InvalidTenantForHost(t *testing.T) {
})
}
}

func TestRunConfigPrepare_EnableSpotInstanceBadSpotAllocationStrategy(t *testing.T) {
c := testConfig()
// There should be some error when Spot Allocation Strategy is invalid.
c.SpotAllocationStrategy = "very-expensive-one"
err := c.Prepare(nil)
if len(err) != 1 {
t.Fatalf("Should error if spot_allocation_strategy is invalid.")
}
}
5 changes: 5 additions & 0 deletions builder/common/step_run_spot_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func getBasicStep() *StepRunSpotInstance {
Region: "us-east-1",
SourceAMI: "",
SpotPrice: "auto",
SpotAllocationStrategy: "price-capacity-optimized",
SpotTags: nil,
Tags: map[string]string{},
VolumeTags: nil,
Expand Down Expand Up @@ -250,6 +251,7 @@ func TestRun(t *testing.T) {
spotRequestId := aws.String("spot-id")
volumeId := aws.String("volume-id")
launchTemplateId := aws.String("launchTemplateId")
spotAllocationStrategy := aws.String("price-capacity-optimized")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId, launchTemplateId)

uiMock := packersdk.TestUi(t)
Expand Down Expand Up @@ -318,6 +320,9 @@ func TestRun(t *testing.T) {
if *ec2Mock.CreateFleetParams[0].LaunchTemplateConfigs[0].LaunchTemplateSpecification.LaunchTemplateName != *launchTemplateName {
t.Fatalf("launchTemplateName should match in createLaunchTemplate and createFleet requests")
}
if *ec2Mock.CreateFleetParams[0].SpotOptions.AllocationStrategy != *spotAllocationStrategy {
t.Fatalf("AllocationStrategy in CreateFleet request should match with spotAllocationStrategy param.")
}

fleetNameTag := ec2Mock.CreateFleetParams[0].TagSpecifications[0].Tags[0]
if *fleetNameTag.Key != "fleet-tag" || *fleetNameTag.Value != "fleet-tag-value" {
Expand Down
8 changes: 4 additions & 4 deletions docs-partials/builder/common/RunConfig-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@
filter, but will cause Packer to fail if the `source_ami` does not exist.

- `spot_allocation_strategy` (string) - One of `price-capacity-optimized`, `capacity-optimized`, `diversified` or `lowest-price`.
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set/set to invalid value, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)
The strategy that determines how to allocate the target Spot Instance capacity
across the Spot Instance pools specified by the EC2 Fleet launch configuration.
If this option is not set, Packer will use default option provided by the SDK (currently `lowest-price`).
For more information, see [Amazon EC2 User Guide] (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html)

- `spot_instance_types` ([]string) - a list of acceptable instance
types to run your build on. We will request a spot instance using the max
Expand Down

0 comments on commit e2ed97d

Please sign in to comment.