feat: scaleway routed ip
Support new network feature "routed ip". IPv4 now attached to the VM directly. Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev> Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
parent
eba5dafb9e
commit
ee67da14c5
@ -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
|
||||
}
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
64
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml
vendored
Normal file
64
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml
vendored
Normal file
@ -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
|
34
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json
vendored
Normal file
34
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user