Skip to content

Commit

Permalink
OpenStack: remove legacy image validation
Browse files Browse the repository at this point in the history
Previously we validate overriden Glance images during generation
of tfvars variables. This is not a correct place to do it, so we
implemented the check in the "validation" module:
openshift#3964

To prevent code duplication we should remove the legacy code.
  • Loading branch information
Fedosin authored and Kenny Woodson committed Nov 30, 2020
1 parent 0ea075b commit 118f8f3
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions pkg/tfvars/openstack/openstack.go
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/utils/openstack/clientconfig"
Expand Down Expand Up @@ -108,13 +107,6 @@ func TFVars(masterConfigs []*v1alpha1.OpenstackProviderSpec, cloud string, exter
if err != nil {
return nil, err
}
} else {
// Not a URL -> use baseImage value as an overridden Glance image name.
// Need to check if this image exists and there are no other images with this name.
err := validateOverriddenImageName(imageName, cloud)
if err != nil {
return nil, err
}
}

glancePublicURL, err := getGlancePublicURL(serviceCatalog)
Expand Down Expand Up @@ -192,41 +184,6 @@ func TFVars(masterConfigs []*v1alpha1.OpenstackProviderSpec, cloud string, exter
return json.MarshalIndent(cfg, "", " ")
}

func validateOverriddenImageName(imageName, cloud string) error {
opts := &clientconfig.ClientOpts{
Cloud: cloud,
}

client, err := clientconfig.NewServiceClient("image", opts)
if err != nil {
return err
}

listOpts := images.ListOpts{
Name: imageName,
}

allPages, err := images.List(client, listOpts).AllPages()
if err != nil {
return err
}

allImages, err := images.ExtractImages(allPages)
if err != nil {
return err
}

if len(allImages) == 0 {
return errors.Errorf("image '%v' doesn't exist", imageName)
}

if len(allImages) > 1 {
return errors.Errorf("there's more than one image with the name '%v'", imageName)
}

return nil
}

// We need to obtain Glance public endpoint that will be used by Ignition to download bootstrap ignition files.
// By design this should be done by using https://www.terraform.io/docs/providers/openstack/d/identity_endpoint_v3.html
// but OpenStack default policies forbid to use this API for regular users.
Expand Down

0 comments on commit 118f8f3

Please sign in to comment.