Skip to content

Commit

Permalink
Removes caching for MAAS availability zones, fetching them fresh each
Browse files Browse the repository at this point in the history
time.

The calls to this method are not frequent enough to attempt
number-of-request amelioration.
  • Loading branch information
manadart committed Apr 1, 2022
1 parent 62be4b1 commit 7226f26
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions provider/maas/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ type maasEnviron struct {
// namespace is used to create the machine and device hostnames.
namespace instance.Namespace

availabilityZonesMutex sync.Mutex
availabilityZones corenetwork.AvailabilityZones

// apiVersion tells us if we are using the MAAS 1.0 or 2.0 api.
apiVersion string

Expand Down Expand Up @@ -534,25 +531,20 @@ func (z maasAvailabilityZone) Available() bool {
// AvailabilityZones returns a slice of availability zones
// for the configured region.
func (env *maasEnviron) AvailabilityZones(ctx context.ProviderCallContext) (corenetwork.AvailabilityZones, error) {
env.availabilityZonesMutex.Lock()
defer env.availabilityZonesMutex.Unlock()
if env.availabilityZones == nil {
var availabilityZones corenetwork.AvailabilityZones
var err error
if env.usingMAAS2() {
availabilityZones, err = env.availabilityZones2(ctx)
if err != nil {
return nil, errors.Trace(err)
}
} else {
availabilityZones, err = env.availabilityZones1(ctx)
if err != nil {
return nil, errors.Trace(err)
}
var zones corenetwork.AvailabilityZones
var err error
if env.usingMAAS2() {
zones, err = env.availabilityZones2(ctx)
if err != nil {
return nil, errors.Trace(err)
}
} else {
zones, err = env.availabilityZones1(ctx)
if err != nil {
return nil, errors.Trace(err)
}
env.availabilityZones = availabilityZones
}
return env.availabilityZones, nil
return zones, nil
}

func (env *maasEnviron) availabilityZones1(ctx context.ProviderCallContext) (corenetwork.AvailabilityZones, error) {
Expand Down

0 comments on commit 7226f26

Please sign in to comment.