Skip to content

Commit 77a4a4a

Browse files
sergelogvinovsmira
authored andcommitted
fix: scaleway metadata
Support legacy-style region values. Disable DHCPv4 for external interface when public IPv4 is disabled. Signed-off-by: Serge Logvinov <[email protected]> Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 7acadc0 commit 77a4a4a

File tree

8 files changed

+150
-32
lines changed

8 files changed

+150
-32
lines changed

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"log"
1212
"net/netip"
1313
"strconv"
14-
"strings"
1514

1615
"github.com/cosi-project/runtime/pkg/state"
1716
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
17+
"github.com/scaleway/scaleway-sdk-go/scw"
1818
"github.com/siderolabs/go-procfs/procfs"
1919

2020
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
@@ -55,7 +55,7 @@ func (s *Scaleway) ParseMetadata(metadata *instance.Metadata) (*runtime.Platform
5555

5656
var publicIPs []string
5757

58-
if metadata.PublicIP.Address != "" {
58+
if metadata.PublicIP.Address != "" && metadata.PublicIP.Family == "inet" {
5959
publicIPs = append(publicIPs, metadata.PublicIP.Address)
6060
}
6161

@@ -74,21 +74,23 @@ func (s *Scaleway) ParseMetadata(metadata *instance.Metadata) (*runtime.Platform
7474
Protocol: nethelpers.ProtocolStatic,
7575
Type: nethelpers.TypeUnicast,
7676
Family: nethelpers.FamilyInet4,
77-
Priority: network.DefaultRouteMetric,
77+
Priority: 4 * network.DefaultRouteMetric,
7878
}
7979

8080
route.Normalize()
8181
networkConfig.Routes = []network.RouteSpecSpec{route}
8282

83-
networkConfig.Operators = append(networkConfig.Operators, network.OperatorSpecSpec{
84-
Operator: network.OperatorDHCP4,
85-
LinkName: "eth0",
86-
RequireUp: true,
87-
DHCP4: network.DHCP4OperatorSpec{
88-
RouteMetric: network.DefaultRouteMetric,
89-
},
90-
ConfigLayer: network.ConfigPlatform,
91-
})
83+
if len(metadata.PublicIpsV4) > 0 {
84+
networkConfig.Operators = append(networkConfig.Operators, network.OperatorSpecSpec{
85+
Operator: network.OperatorDHCP4,
86+
LinkName: "eth0",
87+
RequireUp: true,
88+
DHCP4: network.DHCP4OperatorSpec{
89+
RouteMetric: network.DefaultRouteMetric,
90+
},
91+
ConfigLayer: network.ConfigPlatform,
92+
})
93+
}
9294

9395
if metadata.IPv6.Address != "" || len(metadata.PublicIpsV6) > 0 {
9496
address := metadata.IPv6.Address
@@ -146,25 +148,30 @@ func (s *Scaleway) ParseMetadata(metadata *instance.Metadata) (*runtime.Platform
146148
networkConfig.Routes = append(networkConfig.Routes, route)
147149
}
148150

149-
zoneParts := strings.Split(metadata.Location.ZoneID, "-")
150-
if len(zoneParts) > 2 {
151-
zoneParts = zoneParts[:2]
152-
}
153-
154151
for _, ipStr := range publicIPs {
155152
if ip, err := netip.ParseAddr(ipStr); err == nil {
156153
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
157154
}
158155
}
159156

157+
zone, err := scw.ParseZone(metadata.Location.ZoneID)
158+
if err != nil {
159+
return nil, err
160+
}
161+
162+
region, err := zone.Region()
163+
if err != nil {
164+
return nil, err
165+
}
166+
160167
networkConfig.Metadata = &runtimeres.PlatformMetadataSpec{
161168
Platform: s.Name(),
162169
Hostname: metadata.Hostname,
163-
Region: strings.Join(zoneParts, "-"),
164-
Zone: metadata.Location.ZoneID,
170+
Region: region.String(),
171+
Zone: zone.String(),
165172
InstanceType: metadata.CommercialType,
166173
InstanceID: metadata.ID,
167-
ProviderID: fmt.Sprintf("scaleway://instance/%s/%s", metadata.Location.ZoneID, metadata.ID),
174+
ProviderID: fmt.Sprintf("scaleway://instance/%s/%s", zone.String(), metadata.ID),
168175
}
169176

170177
return networkConfig, nil

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ var rawMetadataV1 []byte
2323
//go:embed testdata/metadata-v2.json
2424
var rawMetadataV2 []byte
2525

26+
//go:embed testdata/metadata-v3.json
27+
var rawMetadataV3 []byte
28+
2629
//go:embed testdata/expected-v1.yaml
2730
var expectedNetworkConfigV1 string
2831

2932
//go:embed testdata/expected-v2.yaml
3033
var expectedNetworkConfigV2 string
3134

35+
//go:embed testdata/expected-v3.yaml
36+
var expectedNetworkConfigV3 string
37+
3238
func TestParseMetadata(t *testing.T) {
3339
p := &scaleway.Scaleway{}
3440

@@ -47,6 +53,11 @@ func TestParseMetadata(t *testing.T) {
4753
raw: rawMetadataV2,
4854
expected: expectedNetworkConfigV2,
4955
},
56+
{
57+
name: "V3",
58+
raw: rawMetadataV3,
59+
expected: expectedNetworkConfigV3,
60+
},
5061
} {
5162
t.Run(tt.name, func(t *testing.T) {
5263
var metadata instance.Metadata

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v1.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ routes:
2020
gateway: ""
2121
outLinkName: eth0
2222
table: main
23-
priority: 1024
23+
priority: 4096
2424
scope: link
2525
type: unicast
2626
flags: ""
@@ -57,8 +57,8 @@ externalIPs:
5757
metadata:
5858
platform: scaleway
5959
hostname: scw-talos
60-
region: zone-name
61-
zone: zone-name-1
60+
region: fr-par
61+
zone: fr-par-1
6262
instanceType: DEV1-S
6363
instanceId: 11111111-1111-1111-1111-111111111111
64-
providerId: scaleway://instance/zone-name-1/11111111-1111-1111-1111-111111111111
64+
providerId: scaleway://instance/fr-par-1/11111111-1111-1111-1111-111111111111

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/expected-v2.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ routes:
2020
gateway: ""
2121
outLinkName: eth0
2222
table: main
23-
priority: 1024
23+
priority: 4096
2424
scope: link
2525
type: unicast
2626
flags: ""
@@ -57,8 +57,8 @@ externalIPs:
5757
metadata:
5858
platform: scaleway
5959
hostname: scw-talos
60-
region: zone-name
61-
zone: zone-name-1
60+
region: fr-par
61+
zone: fr-par-2
6262
instanceType: DEV1-S
6363
instanceId: 11111111-1111-1111-1111-111111111111
64-
providerId: scaleway://instance/zone-name-1/11111111-1111-1111-1111-111111111111
64+
providerId: scaleway://instance/fr-par-2/11111111-1111-1111-1111-111111111111
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
addresses:
2+
- address: 2001:111:222:3333::1/64
3+
linkName: eth0
4+
family: inet6
5+
scope: global
6+
flags: permanent
7+
layer: platform
8+
links:
9+
- name: eth0
10+
logical: false
11+
up: true
12+
mtu: 0
13+
kind: ""
14+
type: netrom
15+
layer: platform
16+
routes:
17+
- family: inet4
18+
dst: 169.254.42.42/32
19+
src: ""
20+
gateway: ""
21+
outLinkName: eth0
22+
table: main
23+
priority: 4096
24+
scope: link
25+
type: unicast
26+
flags: ""
27+
protocol: static
28+
layer: platform
29+
- family: inet6
30+
dst: ""
31+
src: ""
32+
gateway: fe80::dc00:ff:fe12:3456
33+
outLinkName: eth0
34+
table: main
35+
priority: 2048
36+
scope: global
37+
type: unicast
38+
flags: ""
39+
protocol: static
40+
layer: platform
41+
hostnames:
42+
- hostname: scw-talos
43+
domainname: ""
44+
layer: platform
45+
resolvers: []
46+
timeServers: []
47+
operators: []
48+
externalIPs:
49+
- 2001:111:222:3333::1
50+
metadata:
51+
platform: scaleway
52+
hostname: scw-talos
53+
region: nl-ams
54+
zone: nl-ams-1
55+
instanceType: DEV1-S
56+
instanceId: 11111111-1111-1111-1111-111111111111
57+
providerId: scaleway://instance/nl-ams-1/11111111-1111-1111-1111-111111111111

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v1.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,31 @@
88
"public_ip": {
99
"id": "11111111-1111-1111-1111-111111111111",
1010
"address": "11.22.222.222",
11-
"dynamic": false
11+
"dynamic": false,
12+
"family": "inet"
1213
},
14+
"public_ips_v4": [
15+
{
16+
"address": "11.22.222.222",
17+
"dynamic": false,
18+
"family": "inet",
19+
"gateway": null,
20+
"id": "11111111-1111-1111-1111-111111111111",
21+
"ipam_id": null,
22+
"netmask": "32",
23+
"provisioning_mode": "dhcp",
24+
"state": "detached",
25+
"tags": []
26+
}
27+
],
28+
"public_ips_v6": [],
1329
"private_ip": "10.00.222.222",
1430
"ipv6": {
1531
"address": "2001:111:222:3333::1",
1632
"gateway": "2001:111:222:3333::",
1733
"netmask": "64"
1834
},
1935
"location": {
20-
"zone_id": "zone-name-1"
36+
"zone_id": "fr-par-1"
2137
}
2238
}

internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/testdata/metadata-v2.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"public_ip": {
99
"id": "11111111-1111-1111-1111-111111111111",
1010
"address": "11.22.222.222",
11-
"dynamic": false
11+
"dynamic": false,
12+
"family": "inet"
1213
},
1314
"public_ips_v4": [
1415
{
@@ -29,6 +30,6 @@
2930
}
3031
],
3132
"location": {
32-
"zone_id": "zone-name-1"
33+
"zone_id": "fr-par-2"
3334
}
3435
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "11111111-1111-1111-1111-111111111111",
3+
"name": "scw-talos",
4+
"commercial_type": "DEV1-S",
5+
"hostname": "scw-talos",
6+
"tags": [],
7+
"state_detail": "booted",
8+
"public_ip": {
9+
"id": "11111111-1111-1111-1111-111111111111",
10+
"address": "2001:111:222:3333::1",
11+
"dynamic": false
12+
},
13+
"public_ips_v4": [],
14+
"public_ips_v6": [
15+
{
16+
"address": "2001:111:222:3333::1",
17+
"dynamic": false,
18+
"family": "inet6",
19+
"gateway": "fe80::dc00:ff:fe12:3456",
20+
"netmask": "64"
21+
}
22+
],
23+
"location": {
24+
"zone_id": "ams1"
25+
}
26+
}

0 commit comments

Comments
 (0)