Skip to content

Commit

Permalink
check if compute AZ is available
Browse files Browse the repository at this point in the history
Before creating a machine in a given AZ, it'll check that the AZ
actually exists and is available.

JIRA: https://issues.redhat.com/browse/OSASINFRA-1848
Signed-off-by: Emilien Macchi <emilien@redhat.com>
  • Loading branch information
EmilienM committed Dec 8, 2020
1 parent 8a54432 commit 12dc858
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/cloud/openstack/clients/machineservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/pagination"
"github.com/gophercloud/utils/openstack/clientconfig"
azutils "github.com/gophercloud/utils/openstack/compute/v2/availabilityzones"
configclient "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/util"
Expand Down Expand Up @@ -915,6 +916,23 @@ func (is *InstanceService) DoesImageExist(imageName string) error {
return nil
}

// DoesAvailabilityZoneExist return an error if AZ with the given name doesn't exist, and nil otherwise
func (is *InstanceService) DoesAvailabilityZoneExist(azName string) error {
zones, err := azutils.ListAvailableAvailabilityZones(is.computeClient)
if err != nil {
return err
}
if len(zones) == 0 {
return fmt.Errorf("could not find an available compute availability zone")
}
for _, zoneName := range zones {
if zoneName == azName {
return nil
}
}
return fmt.Errorf("could not find compute availability zone: %s", azName)
}

func (is *InstanceService) GetInstance(resourceId string) (instance *Instance, err error) {
if resourceId == "" {
return nil, fmt.Errorf("ResourceId should be specified to get detail.")
Expand Down
6 changes: 6 additions & 0 deletions pkg/cloud/openstack/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,5 +711,11 @@ func (oc *OpenstackClient) validateMachine(machine *machinev1.Machine) error {
return err
}

// Validate that Availability Zone exists
err = machineService.DoesAvailabilityZoneExist(machineSpec.AvailabilityZone)
if err != nil {
return err
}

return nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ github.com/gophercloud/gophercloud/openstack
github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes
github.com/gophercloud/gophercloud/openstack/common/extensions
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs
Expand Down Expand Up @@ -126,6 +127,7 @@ github.com/gophercloud/utils/env
github.com/gophercloud/utils/gnocchi
github.com/gophercloud/utils/internal
github.com/gophercloud/utils/openstack/clientconfig
github.com/gophercloud/utils/openstack/compute/v2/availabilityzones
# github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
github.com/gregjones/httpcache
github.com/gregjones/httpcache/diskcache
Expand Down

0 comments on commit 12dc858

Please sign in to comment.