-
Notifications
You must be signed in to change notification settings - Fork 263
OpenStack single-stack IPv6 support #1909
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
b9f4f6e
9ad66ad
d5f444c
d030c07
aabc1db
b6f610c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,14 @@ package openstack | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net" | ||
| "net/url" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/coreos/ignition/v2/config/v3_6_experimental/types" | ||
|
|
@@ -44,10 +47,18 @@ const ( | |
| ) | ||
|
|
||
| var ( | ||
| metadataServiceUrl = url.URL{ | ||
| Scheme: "http", | ||
| Host: "169.254.169.254", | ||
| Path: "openstack/latest/user_data", | ||
| userdataURLs = map[string]url.URL{ | ||
| resource.IPv4: { | ||
| Scheme: "http", | ||
| Host: "169.254.169.254", | ||
| Path: "openstack/latest/user_data", | ||
| }, | ||
|
|
||
| resource.IPv6: { | ||
| Scheme: "http", | ||
| Host: "[fe80::a9fe:a9fe%iface]", | ||
| Path: "openstack/latest/user_data", | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
|
|
@@ -167,13 +178,61 @@ func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, path string) | |
| } | ||
|
|
||
| func fetchConfigFromMetadataService(f *resource.Fetcher) ([]byte, error) { | ||
prestist marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| res, err := f.FetchToBuffer(metadataServiceUrl, resource.FetchOptions{}) | ||
| urls := map[string]url.URL{ | ||
| string(resource.IPv4): userdataURLs[resource.IPv4], | ||
| } | ||
|
|
||
| ifaceName, err := findInterfaceWithIPv6() | ||
|
||
| if err == nil { | ||
| ipv6Url := userdataURLs[resource.IPv6] | ||
| ipv6Url.Host = strings.Replace(ipv6Url.Host, "iface", ifaceName, 1) | ||
| urls[string(resource.IPv6)] = ipv6Url | ||
| } else { | ||
| f.Logger.Info("No active IPv6 network interface found: %v", err) | ||
| } | ||
|
|
||
| cfg, _, err := resource.FetchConfigDualStack( | ||
| f, | ||
| urls, | ||
| func(f *resource.Fetcher, u url.URL) ([]byte, error) { | ||
| return f.FetchToBuffer(u, resource.FetchOptions{}) | ||
| }, | ||
| ) | ||
|
|
||
| // the metadata server exists but doesn't contain any actual metadata, | ||
| // assume that there is no config specified | ||
| if err == resource.ErrNotFound { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we continue handling the not found error like it was done here? |
||
| return nil, nil | ||
| } | ||
|
|
||
| return res, err | ||
| data, err := json.Marshal(cfg) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return data, nil | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to have some reference on why you are looking for the zone ID in the manner that you are. A simple link to the IPV6 metadata service docs should be good with a quick summary? wdyt? |
||
| func findInterfaceWithIPv6() (string, error) { | ||
|
||
| interfaces, err := net.Interfaces() | ||
| if err != nil { | ||
| return "", fmt.Errorf("error fetching network interfaces: %v", err) | ||
| } | ||
|
|
||
| for _, iface := range interfaces { | ||
| if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 { | ||
| continue | ||
| } | ||
|
|
||
| addrs, err := iface.Addrs() | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| for _, addr := range addrs { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I get a small comment explaining how this is giving us the zoneID? |
||
| if ipnet, ok := addr.(*net.IPNet); ok && ipnet.IP.To16() != nil && ipnet.IP.To4() == nil { | ||
| return iface.Name, nil | ||
| } | ||
| } | ||
| } | ||
| return "", fmt.Errorf("no active IPv6 network interface found") | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are missing a bit of the ipv6
[fe80::a9fe:a9fe%25iface]