diff --git a/pkg/cloud/openstack/clients/machineservice.go b/pkg/cloud/openstack/clients/machineservice.go index 418caae0e9..3efd970aa1 100644 --- a/pkg/cloud/openstack/clients/machineservice.go +++ b/pkg/cloud/openstack/clients/machineservice.go @@ -905,6 +905,16 @@ func (is *InstanceService) DoesFlavorExist(flavorName string) error { return nil } +// DoesImageExist return an error if image with the given name doesn't exist, and nil otherwise +func (is *InstanceService) DoesImageExist(imageName string) error { + _, err := getImageID(is, imageName) + if err != nil { + return err + } + + return nil +} + func (is *InstanceService) GetInstance(resourceId string) (instance *Instance, err error) { if resourceId == "" { return nil, fmt.Errorf("ResourceId should be specified to get detail.") diff --git a/pkg/cloud/openstack/machine/actuator.go b/pkg/cloud/openstack/machine/actuator.go index 5815a63211..e8077a031d 100644 --- a/pkg/cloud/openstack/machine/actuator.go +++ b/pkg/cloud/openstack/machine/actuator.go @@ -675,10 +675,16 @@ func (oc *OpenstackClient) validateMachine(machine *machinev1.Machine) error { // TODO(mfedosin): add more validations here + // Validate that image exists + err = machineService.DoesImageExist(machineSpec.Image) + if err != nil { + return err + } + // Validate that flavor exists err = machineService.DoesFlavorExist(machineSpec.Flavor) if err != nil { - return fmt.Errorf("Can't find a flavor with name %v: %v", machineSpec.Flavor, err) + return err } return nil