Skip to content
Closed
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
9 changes: 9 additions & 0 deletions pkg/asset/machines/aws/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import (
awsutil "github.com/openshift/installer/pkg/asset/installconfig/aws"
)

var cache map[string][]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see this as the following.

var cache = map[string][]string{}

It creates the map when it may never be used. But I don't think that is a terrible cost to pay to avoid having to check for nil in AvailabilityZones. If you want to wait to create the map, then the creation should be down right before the insertion into the map instead of near the read of the map. Go lets you read from a nil map.


// AvailabilityZones retrieves a list of availability zones for the given region.
func AvailabilityZones(region string) ([]string, error) {
if cache == nil {
cache = map[string][]string{}
} else if zones, ok := cache[region]; ok {
return zones, nil
}

ec2Client, err := ec2Client(region)
if err != nil {
return nil, err
Expand All @@ -18,6 +26,7 @@ func AvailabilityZones(region string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("cannot fetch availability zones: %v", err)
}
cache[region] = zones
return zones, nil
}

Expand Down