Skip to content

Image V2: cannot unmarshal string into Go struct field .images.tmp.Properties of type map[string]interface {} #3588

@chanchiwai-ray

Description

@chanchiwai-ray

What happened?

When user provide additional metadata to an image with a key properties, this will cause the unmarshal of Image struct broken.

To reproduce, create an image in glance, and add a property named properties

openstack image set <MY_IMAGE> --properties properties="anything, it can be {'hypervisor_type': 'qemu', 'architecture': 'x86_64'}"

Then, use the sdk to list that image

package main

import (
    "context"

    "github.com/gophercloud/gophercloud/v2"
    "github.com/gophercloud/gophercloud/v2/openstack"
    "github.com/gophercloud/gophercloud/v2/openstack/image/v2/images"
)

func main() {
    ctx := context.Background()

    opts, err := openstack.AuthOptionsFromEnv()
    if err != nil {
        panic(err)
    }

    providerClient, err := openstack.AuthenticatedClient(ctx, opts)
    if err != nil {
        panic(err)
    }

    listOpts := images.ListOpts{
        Name: "<MY_IMAGE>",
    }

    imageClient, err := openstack.NewImageV2(providerClient, gophercloud.EndpointOpts{})
    if err != nil {
        panic(err)
    }

    _, err := images.List(imageClient, listOpts).AllPages(ctx)   # should failed here
    if err != nil {
        panic(err)
    }
}

Useful debugging information to help identify the issue:

openstack image show <MY_IMAGE> --debug

Note the last RESP BODY from the debug output.

This is originally from canonical/openstack-exporter-operator#158

Version

v2 (current)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions