Skip to content

Commit

Permalink
fix: After finding the vmtypes matching the expectations and checking…
Browse files Browse the repository at this point in the history
… spot prices we create the asg to spin the machine using the intial set of vmtypes but it may happen that any of them are not offered on the region of choice for spot price. After the spot price choice picks a region now the instace types are filtered ensuring they are offered

Signed-off-by: Adrian Riobo <ariobolo@redhat.com>
  • Loading branch information
adrianriobo committed Oct 16, 2024
1 parent b1e7cff commit 8d5f496
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pkg/provider/aws/action/fedora/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func Create(r *Request) error {
r.region = so.Region
r.az = so.AvailabilityZone
r.spotPrice = so.MaxPrice
r.VMType, err = data.FilterInstaceTypesOfferedByRegion(r.VMType, r.region)
if err != nil {
return err
}
} else {
r.region = os.Getenv("AWS_DEFAULT_REGION")
az, err := data.GetRandomAvailabilityZone(r.region, nil)
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/aws/action/rhel/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func Create(r *Request) error {
r.region = so.Region
r.az = so.AvailabilityZone
r.spotPrice = so.MaxPrice
r.VMType, err = data.FilterInstaceTypesOfferedByRegion(r.VMType, r.region)
if err != nil {
return err
}
} else {
r.region = os.Getenv("AWS_DEFAULT_REGION")
az, err := data.GetRandomAvailabilityZone(r.region, nil)
Expand Down
19 changes: 14 additions & 5 deletions pkg/provider/aws/data/instance-type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ var (
filternameInstanceType string = "instance-type"
)

// Get InstanceTypes offerings on current location
func IsInstanceTypeOfferedByRegion(instanceType, region string) (bool, error) {
offerings, err := FilterInstaceTypesOfferedByRegion([]string{instanceType}, region)
return len(offerings) == 1, err
}

// Get InstanceTypes offerings on current location
func FilterInstaceTypesOfferedByRegion(instanceTypes []string, region string) ([]string, error) {
var cfgOpts config.LoadOptionsFunc
if len(region) > 0 {
cfgOpts = config.WithRegion(region)
}
cfg, err := config.LoadDefaultConfig(context.TODO(), cfgOpts)
if err != nil {
return false, err
return nil, err
}
client := ec2.NewFromConfig(cfg)
o, err := client.DescribeInstanceTypeOfferings(
Expand All @@ -37,12 +42,16 @@ func IsInstanceTypeOfferedByRegion(instanceType, region string) (bool, error) {
Values: []string{region}},
{
Name: &filternameInstanceType,
Values: []string{instanceType}},
Values: instanceTypes},
}})
if err != nil {
return false, err
return nil, err
}
return len(o.InstanceTypeOfferings) == 1, nil
var offerings []string
for _, o := range o.InstanceTypeOfferings {
offerings = append(offerings, string(o.InstanceType))
}
return offerings, nil
}

func IsInstanceTypeOfferedByAZ(region, instanceType, az string) (bool, error) {
Expand Down

0 comments on commit 8d5f496

Please sign in to comment.