Skip to content

Commit

Permalink
Add single-stack IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
yasminvalim committed Jul 16, 2024
1 parent 1117566 commit 9e7cba8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nav_order: 9
### Features

- Support partitioning disk with mounted partitions
- upport IPv6 for single-stack OpenStack

### Changes

Expand Down
23 changes: 19 additions & 4 deletions internal/providers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -167,13 +172,23 @@ 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 == resource.ErrNotFound {
return nil, nil
} else if err == nil {
return res, nil
}

// the metadata server exists but doesn't contain any actual metadata,
// assume that there is no config specified
// If IPv4 fails, try IPv6 endpoint
res, err = f.FetchToBuffer(ipv6MetadataServiceUrl, resource.FetchOptions{})
if err == resource.ErrNotFound {
return nil, nil
}

// If both endpoints fail, it will return the appropriate error
return res, err
}

0 comments on commit 9e7cba8

Please sign in to comment.