@@ -44,11 +44,16 @@ const (
44
44
)
45
45
46
46
var (
47
- metadataServiceUrl = url.URL {
47
+ ipv4MetadataServiceUrl = url.URL {
48
48
Scheme : "http" ,
49
49
Host : "169.254.169.254" ,
50
50
Path : "openstack/latest/user_data" ,
51
51
}
52
+ ipv6MetadataServiceUrl = url.URL {
53
+ Scheme : "http" ,
54
+ Host : "[fe80::a9fe:a9fe]" ,
55
+ Path : "openstack/latest/user_data" ,
56
+ }
52
57
)
53
58
54
59
func init () {
@@ -167,13 +172,38 @@ func fetchConfigFromDevice(logger *log.Logger, ctx context.Context, path string)
167
172
}
168
173
169
174
func fetchConfigFromMetadataService (f * resource.Fetcher ) ([]byte , error ) {
170
- res , err := f .FetchToBuffer (metadataServiceUrl , resource.FetchOptions {})
175
+ var resIPv4 , resIPv6 []byte
176
+ var errIPv4 , errIPv6 error
171
177
172
- // the metadata server exists but doesn't contain any actual metadata,
173
- // assume that there is no config specified
174
- if err == resource .ErrNotFound {
175
- return nil , nil
178
+ // Try IPv4 endpoint
179
+ resIPv4 , errIPv4 = f .FetchToBuffer (ipv4MetadataServiceUrl , resource.FetchOptions {})
180
+ if errIPv4 != nil && errIPv4 != resource .ErrNotFound {
181
+ f .Logger .Err ("Failed to fetch config from IPv4: %v" , errIPv4 )
182
+ }
183
+
184
+ // Try IPv6 endpoint
185
+ resIPv6 , errIPv6 = f .FetchToBuffer (ipv6MetadataServiceUrl , resource.FetchOptions {})
186
+ if errIPv6 != nil && errIPv6 != resource .ErrNotFound {
187
+ f .Logger .Err ("Failed to fetch config from IPv6: %v" , errIPv6 )
188
+ }
189
+
190
+ // If both IPv4 and IPv6 have valid data, combine them
191
+ if resIPv4 != nil && resIPv6 != nil {
192
+ return append (resIPv4 , resIPv6 ... ), nil
193
+ } else if resIPv4 != nil {
194
+ return resIPv4 , nil
195
+ } else if resIPv6 != nil {
196
+ return resIPv6 , nil
197
+ }
198
+
199
+ // If both endpoints fail, return the appropriate error
200
+ if errIPv4 != nil {
201
+ return nil , errIPv4
202
+ }
203
+ if errIPv6 != nil {
204
+ return nil , errIPv6
176
205
}
177
206
178
- return res , err
207
+ // If both endpoints return ErrNotFound
208
+ return nil , nil
179
209
}
0 commit comments