diff --git a/docs/release-notes.md b/docs/release-notes.md index 8e842f0a2..8be710cfe 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -11,6 +11,7 @@ nav_order: 9 ### Features - Support partitioning disk with mounted partitions +- Support IPv6 for single-stack OpenStack ### Changes diff --git a/internal/providers/openstack/openstack.go b/internal/providers/openstack/openstack.go index 4ef352cfe..2d243db40 100644 --- a/internal/providers/openstack/openstack.go +++ b/internal/providers/openstack/openstack.go @@ -44,11 +44,16 @@ const ( ) var ( - metadataServiceUrl = url.URL{ + ipv4MetadataServiceUrl = url.URL{ Scheme: "http", Host: "169.254.169.254", Path: "openstack/latest/user_data", } + ipv6MetadataServiceUrl = url.URL{ + Scheme: "http", + Host: "[fe80::a9fe:a9fe]", + Path: "openstack/latest/user_data", + } ) func init() { @@ -167,13 +172,25 @@ func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, path string) } func fetchConfigFromMetadataService(f *resource.Fetcher) ([]byte, error) { - res, err := f.FetchToBuffer(metadataServiceUrl, resource.FetchOptions{}) + var res []byte + var err error + + // Try IPv4 endpoint + res, err = f.FetchToBuffer(ipv4MetadataServiceUrl, resource.FetchOptions{}) + if err == nil { + return res, nil + } else if err == resource.ErrNotFound { + return nil, nil + } - // the metadata server exists but doesn't contain any actual metadata, - // assume that there is no config specified - if err == resource.ErrNotFound { + // If IPv4 fails, try IPv6 endpoint + res, err = f.FetchToBuffer(ipv6MetadataServiceUrl, resource.FetchOptions{}) + if err == nil { + return res, nil + } else if err == resource.ErrNotFound { return nil, nil } + // If both endpoints fail, it will return the appropriate error return res, err }