Skip to content

Commit

Permalink
aws/az: creating the types for availability zones
Browse files Browse the repository at this point in the history
  • Loading branch information
mtulio committed Sep 15, 2022
1 parent e911a4d commit 6d9d2d7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions pkg/asset/installconfig/aws/availabilityzones.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
awstypes "github.com/openshift/installer/pkg/types/aws"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func availabilityZones(ctx context.Context, session *session.Session, region str
}
zones := []string{}
for _, zone := range azs {
if *zone.ZoneType == "availability-zone" {
if *zone.ZoneType == awstypes.AvailabilityZoneTypeDefault {
zones = append(zones, *zone.ZoneName)
}
}
Expand All @@ -57,17 +58,17 @@ func localZones(ctx context.Context, session *session.Session, region string) ([

azs, err := describeAvailabilityZones(ctx, session, region)
if err != nil {
return nil, errors.Wrap(err, "fetching availability zones")
return nil, errors.Wrap(err, "fetching availability zones type local-zone")
}
zones := []string{}
for _, zone := range azs {
if *zone.ZoneType == "local-zone" {
if *zone.ZoneType == awstypes.AvailabilityZoneTypeDefault {
zones = append(zones, *zone.ZoneName)
}
}

if len(zones) == 0 {
return nil, errors.Errorf("no available zones type Local in %s", region)
return nil, errors.Errorf("no availability zones type local-zone in %s", region)
}

return zones, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/asset/installconfig/aws/subnet.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
awstypes "github.com/openshift/installer/pkg/types/aws"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -142,7 +143,7 @@ func subnets(ctx context.Context, session *session.Session, region string, ids [
meta.ZoneType = *availabilityZones[meta.Zone].ZoneType

// TODO: Add wavelength-zone when CarrierGateway will be supported on MachineSpec
if meta.ZoneType == "local-zone" {
if meta.ZoneType == awstypes.AvailabilityZoneTypeLocal {
subnets.Edge[id] = meta
} else if isPublic {
subnets.Public[id] = meta
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/aws/validation.go
Expand Up @@ -180,7 +180,7 @@ func validateMachinePool(ctx context.Context, meta *Metadata, fldPath *field.Pat
availableZones := sets.String{}
if len(platform.Subnets) > 0 {
subnets, err := meta.PrivateSubnets(ctx)
if poolName == "edge" {
if poolName == types.InstallConfigPoolNameEdge {
subnets, err = meta.EdgeSubnets(ctx)
}
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/asset/machines/aws/machinesets.go
Expand Up @@ -14,10 +14,6 @@ import (
"github.com/pkg/errors"
)

func isPublicSubnet(subnet string) bool {
return true
}

// MachineSets returns a list of machinesets for a machinepool.
func MachineSets(clusterID string, region string, subnets map[string]string, pool *types.MachinePool, role, userDataSecret string, userTags map[string]string) ([]*machineapi.MachineSet, error) {
if poolPlatform := pool.Platform.Name(); poolPlatform != aws.Name {
Expand Down
2 changes: 0 additions & 2 deletions pkg/asset/machines/worker.go
Expand Up @@ -302,9 +302,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
machineSets = append(machineSets, set)
}
case awstypes.Name:
// here?
subnets := map[string]string{}

if len(ic.Platform.AWS.Subnets) > 0 {
subnetMeta, err := installConfig.AWS.PrivateSubnets(ctx)
if pool.Name == types.InstallConfigPoolNameEdge {
Expand Down
6 changes: 6 additions & 0 deletions pkg/types/aws/availabilityzones.go
@@ -0,0 +1,6 @@
package aws

const (
AvailabilityZoneTypeDefault = "availability-zone"
AvailabilityZoneTypeLocal = "local-zone"
)
1 change: 0 additions & 1 deletion pkg/types/validation/installconfig.go
Expand Up @@ -472,7 +472,6 @@ func validateCompute(platform *types.Platform, control *types.MachinePool, pools
if control != nil && control.Architecture != p.Architecture {
allErrs = append(allErrs, field.Invalid(poolFldPath.Child("architecture"), p.Architecture, "heteregeneous multi-arch is not supported; compute pool architecture must match control plane"))
}

allErrs = append(allErrs, ValidateMachinePool(platform, &p, poolFldPath)...)
}
return allErrs
Expand Down

0 comments on commit 6d9d2d7

Please sign in to comment.