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

Minor fixes around spot and airgap #314

Merged
merged 2 commits into from
Oct 16, 2024
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
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
15 changes: 8 additions & 7 deletions pkg/provider/aws/modules/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,19 @@ func (r *NetworkRequest) manageAirgapNetworking(ctx *pulumi.Context) (

func (r *NetworkRequest) createLoadBalancer(ctx *pulumi.Context,
subnet *ec2.Subnet) (*lb.LoadBalancer, error) {
lbArgs := &lb.LoadBalancerArgs{
LoadBalancerType: pulumi.String("network"),
}
snMapping := &lb.LoadBalancerSubnetMappingArgs{
SubnetId: subnet.ID()}
lbArgs.SubnetMappings = lb.LoadBalancerSubnetMappingArray{
snMapping,
}
// If airgap the load balancer is internal facing
if r.Airgap {
snMapping.PrivateIpv4Address = pulumi.String(internalLBIp)
lbArgs.Internal = pulumi.Bool(true)
}
return lb.NewLoadBalancer(ctx,
resourcesUtil.GetResourceName(r.Prefix, r.ID, "lb"),
&lb.LoadBalancerArgs{
LoadBalancerType: pulumi.String("network"),
SubnetMappings: lb.LoadBalancerSubnetMappingArray{
snMapping,
},
})
resourcesUtil.GetResourceName(r.Prefix, r.ID, "lb"), lbArgs)
}