diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go index 26a005d87b..f0e683e667 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go @@ -90,20 +90,30 @@ func (s *Scaleway) ParseMetadata(metadata *instance.Metadata) (*runtime.Platform ConfigLayer: network.ConfigPlatform, }) - if metadata.IPv6.Address != "" { - bits, err := strconv.Atoi(metadata.IPv6.Netmask) + if metadata.IPv6.Address != "" || len(metadata.PublicIpsV6) > 0 { + address := metadata.IPv6.Address + netmask := metadata.IPv6.Netmask + gateway := metadata.IPv6.Gateway + + if address == "" || netmask == "" || gateway == "" { + address = metadata.PublicIpsV6[0].Address + netmask = metadata.PublicIpsV6[0].Netmask + gateway = metadata.PublicIpsV6[0].Gateway + } + + bits, err := strconv.Atoi(netmask) if err != nil { return nil, err } - ip, err := netip.ParseAddr(metadata.IPv6.Address) + ip, err := netip.ParseAddr(address) if err != nil { return nil, err } addr := netip.PrefixFrom(ip, bits) - publicIPs = append(publicIPs, metadata.IPv6.Address) + publicIPs = append(publicIPs, address) networkConfig.Addresses = append(networkConfig.Addresses, network.AddressSpecSpec{ ConfigLayer: network.ConfigPlatform, @@ -115,7 +125,7 @@ func (s *Scaleway) ParseMetadata(metadata *instance.Metadata) (*runtime.Platform }, ) - gw, err := netip.ParseAddr(metadata.IPv6.Gateway) + gw, err := netip.ParseAddr(gateway) if err != nil { return nil, err } diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go index e3ef3e7235..71184fa8b5 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go @@ -17,24 +17,49 @@ import ( "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway" ) -//go:embed testdata/metadata.json -var rawMetadata []byte +//go:embed testdata/metadata-v1.json +var rawMetadataV1 []byte -//go:embed testdata/expected.yaml -var expectedNetworkConfig string +//go:embed testdata/metadata-v2.json +var rawMetadataV2 []byte + +//go:embed testdata/expected-v1.yaml +var expectedNetworkConfigV1 string + +//go:embed testdata/expected-v2.yaml +var expectedNetworkConfigV2 string func TestParseMetadata(t *testing.T) { p := &scaleway.Scaleway{} - var metadata instance.Metadata + for _, tt := range []struct { + name string + raw []byte + expected string + }{ + { + name: "V1", + raw: rawMetadataV1, + expected: expectedNetworkConfigV1, + }, + { + name: "V2", + raw: rawMetadataV2, + expected: expectedNetworkConfigV2, + }, + } { + t.Run(tt.name, func(t *testing.T) { + var metadata instance.Metadata - require.NoError(t, json.Unmarshal(rawMetadata, &metadata)) + require.NoError(t, json.Unmarshal(tt.raw, &metadata)) - networkConfig, err := p.ParseMetadata(&metadata) - require.NoError(t, err) + networkConfig, err := p.ParseMetadata(&metadata) + require.NoError(t, err) - marshaled, err := yaml.Marshal(networkConfig) - require.NoError(t, err) + marshaled, err := yaml.Marshal(networkConfig) + require.NoError(t, err) - assert.Equal(t, expectedNetworkConfig, string(marshaled)) + assert.Equal(t, tt.expected, string(marshaled)) + }) + } } diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected.yaml b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v1.yaml similarity index 100% rename from internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected.yaml rename to internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v1.yaml diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml new file mode 100644 index 0000000000..9940f8460f --- /dev/null +++ b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml @@ -0,0 +1,64 @@ +addresses: + - address: 2001:111:222:3333::1/64 + linkName: eth0 + family: inet6 + scope: global + flags: permanent + layer: platform +links: + - name: eth0 + logical: false + up: true + mtu: 0 + kind: "" + type: netrom + layer: platform +routes: + - family: inet4 + dst: 169.254.42.42/32 + src: "" + gateway: "" + outLinkName: eth0 + table: main + priority: 1024 + scope: link + type: unicast + flags: "" + protocol: static + layer: platform + - family: inet6 + dst: "" + src: "" + gateway: fe80::dc00:ff:fe12:3456 + outLinkName: eth0 + table: main + priority: 2048 + scope: global + type: unicast + flags: "" + protocol: static + layer: platform +hostnames: + - hostname: scw-talos + domainname: "" + layer: platform +resolvers: [] +timeServers: [] +operators: + - operator: dhcp4 + linkName: eth0 + requireUp: true + dhcp4: + routeMetric: 1024 + layer: platform +externalIPs: + - 11.22.222.222 + - 2001:111:222:3333::1 +metadata: + platform: scaleway + hostname: scw-talos + region: zone-name + zone: zone-name-1 + instanceType: DEV1-S + instanceId: 11111111-1111-1111-1111-111111111111 + providerId: scaleway://instance/zone-name-1/11111111-1111-1111-1111-111111111111 diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata.json b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v1.json similarity index 100% rename from internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata.json rename to internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v1.json diff --git a/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json new file mode 100644 index 0000000000..c717aad1cd --- /dev/null +++ b/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json @@ -0,0 +1,34 @@ +{ + "id": "11111111-1111-1111-1111-111111111111", + "name": "scw-talos", + "commercial_type": "DEV1-S", + "hostname": "scw-talos", + "tags": [], + "state_detail": "booted", + "public_ip": { + "id": "11111111-1111-1111-1111-111111111111", + "address": "11.22.222.222", + "dynamic": false + }, + "public_ips_v4": [ + { + "address": "11.22.222.222", + "dynamic": false, + "family": "inet", + "gateway": "11.22.222.1", + "netmask": "32" + } + ], + "public_ips_v6": [ + { + "address": "2001:111:222:3333::1", + "dynamic": false, + "family": "inet6", + "gateway": "fe80::dc00:ff:fe12:3456", + "netmask": "64" + } + ], + "location": { + "zone_id": "zone-name-1" + } +} \ No newline at end of file