Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Prefer versioned service type aliases #3350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from

Conversation

stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Apr 17, 2025

As discussed in #3349, Gophercloud currently lacks support for version discovery. This means it is reliant on the use of versioned service type aliases (e.g. volumev3) in deployments where there are multiple API versions (and therefore multiple service catalog entries) present for a given service, something that #3209 (and the #3327 backport) failed to account for.

The long-term fix is to add the missing version discovery feature, but that's going to involve a bit of work and rigorous testing. Until we get that done, let's rework things so that we start preferring versioned service types aliases but still fallback to the official service type and the other unversioned service types aliases if necessary. This is achieved via a few discrete steps:

  • We stop overwriting a requested service type when that service type is an alias. Instead, we look for this alias and fallback to using the official service.
  • We sort discovered endpoint in order of the requested service type. This means if we request a service by its service type alias then we will prefer the service that matches this exactly, even if there's another service using the official service type.
  • If we request a service type by a versioned service type alias, ignore services that use a versioned service type with a different version.
  • Finally, revert to using versioned service type aliases for the NewFooVX helpers, thus triggering all of the above.

Fixes #3347

@github-actions github-actions bot added edit:openstack This PR updates common OpenStack code edit:gophercloud This PR updates common Gophercloud code semver:patch No API change labels Apr 17, 2025
@coveralls
Copy link

coveralls commented Apr 17, 2025

Coverage Status

coverage: 63.814% (-0.01%) from 63.828%
when pulling f710413 on stephenfin:discovery-workaround
into 0d4b2d4 on gophercloud:main.

@stephenfin
Copy link
Contributor Author

Here's how I'm testing this using a local DevStack:

  1. Deploy DevStack from master branch.

  2. Create a duplicate of this service plus a fake v2 service (that won't have a valid endpoint). Order is potentially important here so we do the latter first:

    openstack service create volumev2 --name 'cinder_v2'
    openstack service create volumev3 --name 'cinder_v3'
  3. We then create the endpoints for these new services:

    openstack endpoint create cinder_v2 public http://10.0.110.96/volume/v2 --region RegionOne
    openstack endpoint create cinder_v3 public http://10.0.110.96/volume/v3 --region RegionOne
  4. Validate by running the below "script". I'm using replace to point to my local repo with this PR checked out. I've also added some addition debug prints to openstack/endpoint_location.go to demonstrate that the volumev2 endpoint is skipped and that the volumev3 is preferred as a closer match, with block-storage still selected as an alternative.

I would appreciate anyone that has run into this issue doing the same, perhaps with modifications to use shares instead of volumes.


main.go =>

package main

import (
        "context"
        "fmt"
        "os"

        "github.com/gophercloud/gophercloud/v2"
        "github.com/gophercloud/gophercloud/v2/openstack"
        "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes"
)

func main() {
        ao, err := openstack.AuthOptionsFromEnv()
        if err != nil {
                panic(err)
        }

        client, err := openstack.AuthenticatedClient(context.TODO(), ao)
        if err != nil {
                panic(err)
        }

        blockStorage, err := openstack.NewBlockStorageV3(client, gophercloud.EndpointOpts{Region: os.Getenv("OS_REGION_NAME")})
        if err != nil {
                panic(err)
        }

        pager, err := volumes.List(blockStorage, nil).AllPages(context.TODO())
        if err != nil {
                fmt.Println(err)
                return
        }

        volumes, err := volumes.ExtractVolumes(pager)
        if err != nil {
                fmt.Println(err)
                return
        }

        fmt.Println("volumes:")
        for i, volume := range volumes {
                fmt.Printf("  volume %d: id=%s\n", i, volume.ID)
        }
}

go.mod =>

module gophercloud-version-workaround

go 1.23.8

require github.com/gophercloud/gophercloud/v2 v2.7.0

replace github.com/gophercloud/gophercloud/v2 => /home/stephenfin/code/gophercloud/gophercloud

We do not need to check the validity of the provided opts more than once
so don't. We can also simplify our handling of multiple endpoints.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
As noted inline, this allows us to prefer what the user (or we) requested
until such a time as this is no longer necessary.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Currently, we iterate through endpoints first, comparing them to the
request service type and its aliases. This means that endpoints which
use an alias can end up being selected ahead of endpoints that use the
requested type. Invert this logic so that we prefer endpoints that match
our requested type ahead of those that match an alias of the requested
type.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
If we requested volumev2 then we obviously don't want to match on
volumev3.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This is a partial revert of e394733.
Prefer e.g. volumev3 or sharev2 to block-storage or shared-file-systems
as a temporary measure while we work on versioned API discovery. Couple
with prior changes, this means if we e.g. have two catalog entries with
services types of 'volumev2' and 'volumev3' (in that order!) and we
request a service with 'volumev3', we will return the latter catalog
entry ahead of the former.

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
@stephenfin stephenfin force-pushed the discovery-workaround branch from 18206ab to f710413 Compare May 16, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edit:gophercloud This PR updates common Gophercloud code edit:openstack This PR updates common OpenStack code semver:patch No API change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in 2.7.0: openstack.NewSharedFilesystemV2 chooses v1 API
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.