Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/provider/api/compute-request/compute-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
Amd64 Arch = iota + 1
Arm64

MaxResults = 15 // maximum number of VM types to fetch
MaxResults = 20 // maximum number of VM types to fetch
)

type Arch int
Expand Down
15 changes: 9 additions & 6 deletions pkg/provider/aws/data/spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var placementScores = []placementScoreSpec{
// While calculating the spot price and the types of machines
// to be requested we use the first n number of types per Az
// to control how many types will be used this var is used
var numberOfTypesForSpot = 5
var numberOfTypesForSpot = 8

func minPlacementScore(spotTolerance spot.Tolerance) int32 {
idx := slices.IndexFunc(placementScores,
Expand Down Expand Up @@ -186,6 +186,7 @@ func SpotInfo(mCtx *mc.Context, args *SpotInfoArgs) (*spot.SpotResults, error) {
regionsWithPlacementScore := utilMaps.Keys(placementScores)
spotPricing, err := hostingPlaces.RunOnHostingPlaces(regionsWithPlacementScore,
spotPricingArgs{
mCtx: mCtx,
productDescription: *args.ProductDescription,
instanceTypes: args.InstaceTypes,
},
Expand Down Expand Up @@ -285,6 +286,7 @@ func aggregateSpotChoice(s []*SpotInfoResult) *SpotInfoResult {
}

type spotPricingArgs struct {
mCtx *mc.Context
productDescription string
instanceTypes []string
}
Expand Down Expand Up @@ -334,10 +336,11 @@ func spotPricingAsync(r string, args spotPricingArgs, c chan hostingPlaces.Hosti
InstanceType: string(priceData.InstanceType),
}
})

for _, v := range spotPriceGroups {
for _, sp := range v {
logging.Debugf("Found InstanceType %s at Availability Zone %s with spot price %s", string(sp.InstanceType), *sp.AvailabilityZone, *sp.SpotPrice)
if args.mCtx.Debug() {
for _, v := range spotPriceGroups {
for _, sp := range v {
logging.Debugf("Found InstanceType %s at Availability Zone %s with spot price %s", string(sp.InstanceType), *sp.AvailabilityZone, *sp.SpotPrice)
}
}
}
var results []spotPrincingResults
Expand Down Expand Up @@ -419,7 +422,7 @@ func placementScoresAsync(r string, args placementScoreArgs, c chan hostingPlace
}
slices.SortFunc(results,
func(a, b placementScoreResult) int {
return int(*a.sps.Score - *b.sps.Score)
return int(*b.sps.Score - *a.sps.Score)
})
c <- hostingPlaces.HostingPlaceData[[]placementScoreResult]{
Region: r,
Expand Down
39 changes: 25 additions & 14 deletions pkg/provider/aws/modules/allocation/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,31 @@ func allocationSpot(mCtx *mc.Context,

func allocationOnDemand(instancesTypes []string) (*AllocationResult, error) {
region := os.Getenv("AWS_DEFAULT_REGION")
az, err := data.GetRandomAvailabilityZone(region, nil)
if err != nil {
return nil, err
}
supportedInstancesType, err :=
data.FilterInstaceTypesOfferedByLocation(instancesTypes, &data.LocationArgs{
Region: &region,
Az: az,
})
if err != nil {
return nil, err
}
if len(supportedInstancesType) == 0 {
return nil, ErrNoSupportedInstaceTypes
excludedAZs := []string{}
var err error
var az *string
var supportedInstancesType []string
azs := data.GetAvailabilityZones(region, nil)
for {
az, err = data.GetRandomAvailabilityZone(region, excludedAZs)
if err != nil {
return nil, err
}
supportedInstancesType, err =
data.FilterInstaceTypesOfferedByLocation(instancesTypes, &data.LocationArgs{
Region: &region,
Az: az,
})
if err != nil {
return nil, err
}
if len(supportedInstancesType) > 0 {
break
}
excludedAZs = append(excludedAZs, *az)
if len(excludedAZs) == len(azs) {
return nil, ErrNoSupportedInstaceTypes
}
}
return &AllocationResult{
Region: &region,
Expand Down
26 changes: 13 additions & 13 deletions pkg/provider/aws/services/vpc/subnet/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type PublicSubnetResources struct {
Subnet *ec2.Subnet
RouteTable *ec2.RouteTable
RouteTableAssociation *ec2.RouteTableAssociation
EIP *ec2.Eip
NatGateway *ec2.NatGateway
NatGatewayEip *ec2.Eip
}

func (r PublicSubnetRequest) Create(ctx *pulumi.Context, mCtx *mc.Context) (*PublicSubnetResources, error) {
Expand All @@ -41,22 +41,22 @@ func (r PublicSubnetRequest) Create(ctx *pulumi.Context, mCtx *mc.Context) (*Pub
if err != nil {
return nil, err
}
eipName := fmt.Sprintf("%s-%s", "eip", r.Name)
eip, err := ec2.NewEip(ctx,
eipName,
&ec2.EipArgs{
Domain: pulumi.String("vpc"),
})
if err != nil {
return nil, err
}
var nEip *ec2.Eip
var n *ec2.NatGateway
if r.AddNatGateway {
nEip, err := ec2.NewEip(ctx,
fmt.Sprintf("%s-%s", "eip", r.Name),
&ec2.EipArgs{
Domain: pulumi.String("vpc"),
})
if err != nil {
return nil, err
}
nName := fmt.Sprintf("%s-%s", "natgateway", r.Name)
n, err = ec2.NewNatGateway(ctx,
nName,
&ec2.NatGatewayArgs{
AllocationId: eip.ID(),
AllocationId: nEip.ID(),
SubnetId: sn.ID(),
Tags: mCtx.ResourceTags(),
})
Expand Down Expand Up @@ -93,7 +93,7 @@ func (r PublicSubnetRequest) Create(ctx *pulumi.Context, mCtx *mc.Context) (*Pub
Subnet: sn,
RouteTable: rt,
RouteTableAssociation: rta,
EIP: eip,
NatGateway: n},
NatGateway: n,
NatGatewayEip: nEip},
nil
}