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 23, 2024
1 parent 1117566 commit a850f29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 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
- Support IPv6 for single-stack OpenStack

### Changes

Expand Down
44 changes: 37 additions & 7 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,38 @@ 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 resIPv4, resIPv6 []byte
var errIPv4, errIPv6 error

// the metadata server exists but doesn't contain any actual metadata,
// assume that there is no config specified
if err == resource.ErrNotFound {
return nil, nil
// Try IPv4 endpoint
resIPv4, errIPv4 = f.FetchToBuffer(ipv4MetadataServiceUrl, resource.FetchOptions{})
if errIPv4 != nil && errIPv4 != resource.ErrNotFound {
f.Logger.Err("Failed to fetch config from IPv4: %v", errIPv4)
}

// Try IPv6 endpoint
resIPv6, errIPv6 = f.FetchToBuffer(ipv6MetadataServiceUrl, resource.FetchOptions{})
if errIPv6 != nil && errIPv6 != resource.ErrNotFound {
f.Logger.Err("Failed to fetch config from IPv6: %v", errIPv6)
}

// If both IPv4 and IPv6 have valid data, combine them
if resIPv4 != nil && resIPv6 != nil {
return append(resIPv4, resIPv6...), nil
} else if resIPv4 != nil {
return resIPv4, nil
} else if resIPv6 != nil {
return resIPv6, nil
}

// If both endpoints fail, return the appropriate error
if errIPv4 != nil {
return nil, errIPv4
}
if errIPv6 != nil {
return nil, errIPv6
}

return res, err
// If both endpoints return ErrNotFound
return nil, nil
}

0 comments on commit a850f29

Please sign in to comment.