forked from openshift/ovn-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_annotations.go
557 lines (490 loc) · 19.2 KB
/
node_annotations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
package util
import (
"encoding/json"
"fmt"
"math"
"net"
"strconv"
kapi "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube"
)
// This handles the annotations used by the node to pass information about its local
// network configuration to the master:
//
// annotations:
// k8s.ovn.org/l3-gateway-config: |
// {
// "default": {
// "mode": "local",
// "interface-id": "br-local_ip-10-0-129-64.us-east-2.compute.internal",
// "mac-address": "f2:20:a0:3c:26:4c",
// "ip-addresses": ["169.254.33.2/24"],
// "next-hops": ["169.254.33.1"],
// "node-port-enable": "true",
// "vlan-id": "0"
//
// # backward-compat
// "ip-address": "169.254.33.2/24",
// "next-hop": "169.254.33.1",
// }
// }
// k8s.ovn.org/node-chassis-id: b1f96182-2bdd-42b6-88f9-9a1fc1c85ece
// k8s.ovn.org/node-mgmt-port-mac-address: fa:f1:27:f5:54:69
//
// The "ip_address" and "next_hop" fields are deprecated and will eventually go away.
// (And they are not output when "ip_addresses" or "next_hops" contains multiple
// values.)
const (
// ovnNodeL3GatewayConfig is the constant string representing the l3 gateway annotation key
ovnNodeL3GatewayConfig = "k8s.ovn.org/l3-gateway-config"
// ovnNodeGatewayMtuSupport determines if option:gateway_mtu shall be set for GR router ports.
ovnNodeGatewayMtuSupport = "k8s.ovn.org/gateway-mtu-support"
// OvnDefaultNetworkGateway captures L3 gateway config for default OVN network interface
ovnDefaultNetworkGateway = "default"
// ovnNodeManagementPortMacAddress is the constant string representing the annotation key
ovnNodeManagementPortMacAddress = "k8s.ovn.org/node-mgmt-port-mac-address"
// ovnNodeChassisID is the systemID of the node needed for creating L3 gateway
ovnNodeChassisID = "k8s.ovn.org/node-chassis-id"
// ovnNodeCIDR is the CIDR form representation of primary network interface's attached IP address (i.e: 192.168.126.31/24 or 0:0:0:0:0:feff:c0a8:8e0c/64)
ovnNodeIfAddr = "k8s.ovn.org/node-primary-ifaddr"
// ovnNodeGRLRPAddr is the CIDR form representation of Gate Router LRP IP address to join switch (i.e: 100.64.0.5/24)
ovnNodeGRLRPAddr = "k8s.ovn.org/node-gateway-router-lrp-ifaddr"
// OvnNodeEgressLabel is a user assigned node label indicating to ovn-kubernetes that the node is to be used for egress IP assignment
ovnNodeEgressLabel = "k8s.ovn.org/egress-assignable"
// ovnNodeHostAddresses is used to track the different host IP addresses on the node
ovnNodeHostAddresses = "k8s.ovn.org/host-addresses"
// egressIPConfigAnnotationKey is used to indicate the cloud subnet and
// capacity for each node. It is set by
// openshift/cloud-network-config-controller
cloudEgressIPConfigAnnotationKey = "cloud.network.openshift.io/egress-ipconfig"
)
type L3GatewayConfig struct {
Mode config.GatewayMode
ChassisID string
InterfaceID string
MACAddress net.HardwareAddr
IPAddresses []*net.IPNet
EgressGWInterfaceID string
EgressGWMACAddress net.HardwareAddr
EgressGWIPAddresses []*net.IPNet
NextHops []net.IP
NodePortEnable bool
VLANID *uint
}
type l3GatewayConfigJSON struct {
Mode config.GatewayMode `json:"mode"`
InterfaceID string `json:"interface-id,omitempty"`
MACAddress string `json:"mac-address,omitempty"`
IPAddresses []string `json:"ip-addresses,omitempty"`
IPAddress string `json:"ip-address,omitempty"`
EgressGWInterfaceID string `json:"exgw-interface-id,omitempty"`
EgressGWMACAddress string `json:"exgw-mac-address,omitempty"`
EgressGWIPAddresses []string `json:"exgw-ip-addresses,omitempty"`
EgressGWIPAddress string `json:"exgw-ip-address,omitempty"`
NextHops []string `json:"next-hops,omitempty"`
NextHop string `json:"next-hop,omitempty"`
NodePortEnable string `json:"node-port-enable,omitempty"`
VLANID string `json:"vlan-id,omitempty"`
}
func (cfg *L3GatewayConfig) MarshalJSON() ([]byte, error) {
cfgjson := l3GatewayConfigJSON{
Mode: cfg.Mode,
}
if cfg.Mode == config.GatewayModeDisabled {
return json.Marshal(&cfgjson)
}
cfgjson.InterfaceID = cfg.InterfaceID
cfgjson.MACAddress = cfg.MACAddress.String()
cfgjson.EgressGWInterfaceID = cfg.EgressGWInterfaceID
cfgjson.EgressGWMACAddress = cfg.EgressGWMACAddress.String()
cfgjson.NodePortEnable = fmt.Sprintf("%t", cfg.NodePortEnable)
if cfg.VLANID != nil {
cfgjson.VLANID = fmt.Sprintf("%d", *cfg.VLANID)
}
cfgjson.IPAddresses = make([]string, len(cfg.IPAddresses))
for i, ip := range cfg.IPAddresses {
cfgjson.IPAddresses[i] = ip.String()
}
if len(cfgjson.IPAddresses) == 1 {
cfgjson.IPAddress = cfgjson.IPAddresses[0]
}
cfgjson.EgressGWIPAddresses = make([]string, len(cfg.EgressGWIPAddresses))
for i, ip := range cfg.EgressGWIPAddresses {
cfgjson.EgressGWIPAddresses[i] = ip.String()
}
if len(cfgjson.EgressGWIPAddresses) == 1 {
cfgjson.EgressGWIPAddress = cfgjson.EgressGWIPAddresses[0]
}
cfgjson.NextHops = make([]string, len(cfg.NextHops))
for i, nh := range cfg.NextHops {
cfgjson.NextHops[i] = nh.String()
}
if len(cfgjson.NextHops) == 1 {
cfgjson.NextHop = cfgjson.NextHops[0]
}
return json.Marshal(&cfgjson)
}
func (cfg *L3GatewayConfig) UnmarshalJSON(bytes []byte) error {
cfgjson := l3GatewayConfigJSON{}
if err := json.Unmarshal(bytes, &cfgjson); err != nil {
return err
}
cfg.Mode = cfgjson.Mode
if cfg.Mode == config.GatewayModeDisabled {
return nil
} else if cfg.Mode != config.GatewayModeShared && cfg.Mode != config.GatewayModeLocal {
return fmt.Errorf("bad 'mode' value %q", cfgjson.Mode)
}
cfg.InterfaceID = cfgjson.InterfaceID
cfg.EgressGWInterfaceID = cfgjson.EgressGWInterfaceID
cfg.NodePortEnable = cfgjson.NodePortEnable == "true"
if cfgjson.VLANID != "" {
vlanID64, err := strconv.ParseUint(cfgjson.VLANID, 10, 0)
if err != nil {
return fmt.Errorf("bad 'vlan-id' value %q: %v", cfgjson.VLANID, err)
}
// VLANID is used for specifying TagRequest on the logical switch port
// connected to the external logical switch, NB DB specifies a maximum
// value on the TagRequest to 4095, hence validate this:
//https://github.com/ovn-org/ovn/blob/4b97d6fa88e36206213b9fdc8e1e1a9016cfc736/ovn-nb.ovsschema#L94-L98
if vlanID64 > 4095 {
return fmt.Errorf("vlan-id surpasses maximum supported value")
}
vlanID := uint(vlanID64)
cfg.VLANID = &vlanID
}
var err error
cfg.MACAddress, err = net.ParseMAC(cfgjson.MACAddress)
if err != nil {
return fmt.Errorf("bad 'mac-address' value %q: %v", cfgjson.MACAddress, err)
}
if cfg.EgressGWInterfaceID != "" {
cfg.EgressGWMACAddress, err = net.ParseMAC(cfgjson.EgressGWMACAddress)
if err != nil {
return fmt.Errorf("bad 'egress mac-address' value %q: %v", cfgjson.EgressGWMACAddress, err)
}
if len(cfgjson.EgressGWIPAddresses) == 0 {
cfg.EgressGWIPAddresses = make([]*net.IPNet, 1)
ip, ipnet, err := net.ParseCIDR(cfgjson.EgressGWIPAddress)
if err != nil {
return fmt.Errorf("bad 'ip-address' value %q: %v", cfgjson.EgressGWIPAddress, err)
}
cfg.EgressGWIPAddresses[0] = &net.IPNet{IP: ip, Mask: ipnet.Mask}
} else {
cfg.EgressGWIPAddresses = make([]*net.IPNet, len(cfgjson.EgressGWIPAddresses))
for i, ipStr := range cfgjson.EgressGWIPAddresses {
ip, ipnet, err := net.ParseCIDR(ipStr)
if err != nil {
return fmt.Errorf("bad 'ip-addresses' value %q: %v", ipStr, err)
}
cfg.EgressGWIPAddresses[i] = &net.IPNet{IP: ip, Mask: ipnet.Mask}
}
}
}
if len(cfgjson.IPAddresses) == 0 {
cfg.IPAddresses = make([]*net.IPNet, 1)
ip, ipnet, err := net.ParseCIDR(cfgjson.IPAddress)
if err != nil {
return fmt.Errorf("bad 'ip-address' value %q: %v", cfgjson.IPAddress, err)
}
cfg.IPAddresses[0] = &net.IPNet{IP: ip, Mask: ipnet.Mask}
} else {
cfg.IPAddresses = make([]*net.IPNet, len(cfgjson.IPAddresses))
for i, ipStr := range cfgjson.IPAddresses {
ip, ipnet, err := net.ParseCIDR(ipStr)
if err != nil {
return fmt.Errorf("bad 'ip-addresses' value %q: %v", ipStr, err)
}
cfg.IPAddresses[i] = &net.IPNet{IP: ip, Mask: ipnet.Mask}
}
}
cfg.NextHops = make([]net.IP, len(cfgjson.NextHops))
for i, nextHopStr := range cfgjson.NextHops {
cfg.NextHops[i] = net.ParseIP(nextHopStr)
if cfg.NextHops[i] == nil {
return fmt.Errorf("bad 'next-hops' value %q", nextHopStr)
}
}
return nil
}
func SetL3GatewayConfig(nodeAnnotator kube.Annotator, cfg *L3GatewayConfig) error {
gatewayAnnotation := map[string]*L3GatewayConfig{ovnDefaultNetworkGateway: cfg}
if err := nodeAnnotator.Set(ovnNodeL3GatewayConfig, gatewayAnnotation); err != nil {
return err
}
if cfg.ChassisID != "" {
if err := nodeAnnotator.Set(ovnNodeChassisID, cfg.ChassisID); err != nil {
return err
}
}
return nil
}
// SetGatewayMTUSupport sets annotation "k8s.ovn.org/gateway-mtu-support" to "false" or removes the annotation from
// this node.
func SetGatewayMTUSupport(nodeAnnotator kube.Annotator, set bool) error {
if set {
nodeAnnotator.Delete(ovnNodeGatewayMtuSupport)
return nil
}
return nodeAnnotator.Set(ovnNodeGatewayMtuSupport, "false")
}
// ParseNodeGatewayMTUSupport parses annotation "k8s.ovn.org/gateway-mtu-support". The default behavior should be true,
// therefore only an explicit string of "false" will make this function return false.
func ParseNodeGatewayMTUSupport(node *kapi.Node) bool {
return node.Annotations[ovnNodeGatewayMtuSupport] != "false"
}
// ParseNodeL3GatewayAnnotation returns the parsed l3-gateway-config annotation
func ParseNodeL3GatewayAnnotation(node *kapi.Node) (*L3GatewayConfig, error) {
l3GatewayAnnotation, ok := node.Annotations[ovnNodeL3GatewayConfig]
if !ok {
return nil, newAnnotationNotSetError("%s annotation not found for node %q", ovnNodeL3GatewayConfig, node.Name)
}
var cfgs map[string]*L3GatewayConfig
if err := json.Unmarshal([]byte(l3GatewayAnnotation), &cfgs); err != nil {
return nil, fmt.Errorf("failed to unmarshal l3 gateway config annotation %s for node %q: %v", l3GatewayAnnotation, node.Name, err)
}
cfg, ok := cfgs[ovnDefaultNetworkGateway]
if !ok {
return nil, fmt.Errorf("%s annotation for %s network not found", ovnNodeL3GatewayConfig, ovnDefaultNetworkGateway)
}
if cfg.Mode != config.GatewayModeDisabled {
cfg.ChassisID, ok = node.Annotations[ovnNodeChassisID]
if !ok {
return nil, fmt.Errorf("%s annotation not found", ovnNodeChassisID)
}
}
return cfg, nil
}
func NodeL3GatewayAnnotationChanged(oldNode, newNode *kapi.Node) bool {
return oldNode.Annotations[ovnNodeL3GatewayConfig] != newNode.Annotations[ovnNodeL3GatewayConfig]
}
// ParseNodeChassisIDAnnotation returns the node's ovnNodeChassisID annotation
func ParseNodeChassisIDAnnotation(node *kapi.Node) (string, error) {
chassisID, ok := node.Annotations[ovnNodeChassisID]
if !ok {
return "", newAnnotationNotSetError("%s annotation not found for node %s", ovnNodeChassisID, node.Name)
}
return chassisID, nil
}
func NodeChassisIDAnnotationChanged(oldNode, newNode *kapi.Node) bool {
return oldNode.Annotations[ovnNodeChassisID] != newNode.Annotations[ovnNodeChassisID]
}
func SetNodeManagementPortMACAddress(nodeAnnotator kube.Annotator, macAddress net.HardwareAddr) error {
return nodeAnnotator.Set(ovnNodeManagementPortMacAddress, macAddress.String())
}
func ParseNodeManagementPortMACAddress(node *kapi.Node) (net.HardwareAddr, error) {
macAddress, ok := node.Annotations[ovnNodeManagementPortMacAddress]
if !ok {
return nil, newAnnotationNotSetError("macAddress annotation not found for node %q ", node.Name)
}
return net.ParseMAC(macAddress)
}
type primaryIfAddrAnnotation struct {
IPv4 string `json:"ipv4,omitempty"`
IPv6 string `json:"ipv6,omitempty"`
}
// SetNodePrimaryIfAddr sets the IPv4 / IPv6 values of the node's primary network interface
func SetNodePrimaryIfAddrs(nodeAnnotator kube.Annotator, ifAddrs []*net.IPNet) (err error) {
nodeIPNetv4, _ := MatchFirstIPNetFamily(false, ifAddrs)
nodeIPNetv6, _ := MatchFirstIPNetFamily(true, ifAddrs)
primaryIfAddrAnnotation := primaryIfAddrAnnotation{}
if nodeIPNetv4 != nil {
primaryIfAddrAnnotation.IPv4 = nodeIPNetv4.String()
}
if nodeIPNetv6 != nil {
primaryIfAddrAnnotation.IPv6 = nodeIPNetv6.String()
}
return nodeAnnotator.Set(ovnNodeIfAddr, primaryIfAddrAnnotation)
}
// CreateNodeGatewayRouterLRPAddrAnnotation sets the IPv4 / IPv6 values of the node's Gatewary Router LRP to join switch.
func CreateNodeGatewayRouterLRPAddrAnnotation(nodeAnnotation map[string]string, nodeIPNetv4,
nodeIPNetv6 *net.IPNet) (map[string]string, error) {
if nodeAnnotation == nil {
nodeAnnotation = map[string]string{}
}
primaryIfAddrAnnotation := primaryIfAddrAnnotation{}
if nodeIPNetv4 != nil {
primaryIfAddrAnnotation.IPv4 = nodeIPNetv4.String()
}
if nodeIPNetv6 != nil {
primaryIfAddrAnnotation.IPv6 = nodeIPNetv6.String()
}
bytes, err := json.Marshal(primaryIfAddrAnnotation)
if err != nil {
return nil, err
}
nodeAnnotation[ovnNodeGRLRPAddr] = string(bytes)
return nodeAnnotation, nil
}
const UnlimitedNodeCapacity = math.MaxInt32
type ifAddr struct {
IPv4 string `json:"ipv4,omitempty"`
IPv6 string `json:"ipv6,omitempty"`
}
type Capacity struct {
IPv4 int `json:"ipv4,omitempty"`
IPv6 int `json:"ipv6,omitempty"`
IP int `json:"ip,omitempty"`
}
type nodeEgressIPConfiguration struct {
Interface string `json:"interface"`
IFAddr ifAddr `json:"ifaddr"`
Capacity Capacity `json:"capacity"`
}
type ParsedIFAddr struct {
IP net.IP
Net *net.IPNet
}
type ParsedNodeEgressIPConfiguration struct {
V4 ParsedIFAddr
V6 ParsedIFAddr
Capacity Capacity
}
func getNodeIfAddrAnnotation(node *kapi.Node) (*primaryIfAddrAnnotation, error) {
nodeIfAddrAnnotation, ok := node.Annotations[ovnNodeIfAddr]
if !ok {
return nil, newAnnotationNotSetError("%s annotation not found for node %q", ovnNodeIfAddr, node.Name)
}
nodeIfAddr := &primaryIfAddrAnnotation{}
if err := json.Unmarshal([]byte(nodeIfAddrAnnotation), nodeIfAddr); err != nil {
return nil, fmt.Errorf("failed to unmarshal annotation: %s for node %q, err: %v", ovnNodeIfAddr, node.Name, err)
}
if nodeIfAddr.IPv4 == "" && nodeIfAddr.IPv6 == "" {
return nil, fmt.Errorf("node: %q does not have any IP information set", node.Name)
}
return nodeIfAddr, nil
}
// ParseNodePrimaryIfAddr returns the IPv4 / IPv6 values for the node's primary network interface
func ParseNodePrimaryIfAddr(node *kapi.Node) (*ParsedNodeEgressIPConfiguration, error) {
nodeIfAddr, err := getNodeIfAddrAnnotation(node)
if err != nil {
return nil, err
}
nodeEgressIPConfig := nodeEgressIPConfiguration{
IFAddr: ifAddr(*nodeIfAddr),
Capacity: Capacity{
IP: UnlimitedNodeCapacity,
IPv4: UnlimitedNodeCapacity,
IPv6: UnlimitedNodeCapacity,
},
}
parsedEgressIPConfig, err := parseNodeEgressIPConfig(&nodeEgressIPConfig)
if err != nil {
return nil, err
}
return parsedEgressIPConfig, nil
}
// ParseNodeGatewayRouterLRPAddr returns the IPv4 / IPv6 values for the node's gateway router
func ParseNodeGatewayRouterLRPAddr(node *kapi.Node) (net.IP, error) {
nodeIfAddrAnnotation, ok := node.Annotations[ovnNodeGRLRPAddr]
if !ok {
return nil, newAnnotationNotSetError("%s annotation not found for node %q", ovnNodeGRLRPAddr, node.Name)
}
nodeIfAddr := primaryIfAddrAnnotation{}
if err := json.Unmarshal([]byte(nodeIfAddrAnnotation), &nodeIfAddr); err != nil {
return nil, fmt.Errorf("failed to unmarshal annotation: %s for node %q, err: %v", ovnNodeGRLRPAddr, node.Name, err)
}
if nodeIfAddr.IPv4 == "" && nodeIfAddr.IPv6 == "" {
return nil, fmt.Errorf("node: %q does not have any IP information set", node.Name)
}
ip, _, err := net.ParseCIDR(nodeIfAddr.IPv4)
if err != nil {
return nil, fmt.Errorf("failed to parse annotation: %s for node %q, err: %v", ovnNodeGRLRPAddr, node.Name, err)
}
return ip, nil
}
// ParseCloudEgressIPConfig returns the cloud's information concerning the node's primary network interface
func ParseCloudEgressIPConfig(node *kapi.Node) (*ParsedNodeEgressIPConfiguration, error) {
egressIPConfigAnnotation, ok := node.Annotations[cloudEgressIPConfigAnnotationKey]
if !ok {
return nil, newAnnotationNotSetError("%s annotation not found for node %q", cloudEgressIPConfigAnnotationKey, node.Name)
}
nodeEgressIPConfig := []nodeEgressIPConfiguration{
{
Capacity: Capacity{
IP: UnlimitedNodeCapacity,
IPv4: UnlimitedNodeCapacity,
IPv6: UnlimitedNodeCapacity,
},
},
}
if err := json.Unmarshal([]byte(egressIPConfigAnnotation), &nodeEgressIPConfig); err != nil {
return nil, fmt.Errorf("failed to unmarshal annotation: %s for node %q, err: %v", ovnNodeIfAddr, node.Name, err)
}
if len(nodeEgressIPConfig) == 0 {
return nil, fmt.Errorf("empty annotation: %s for node: %q", cloudEgressIPConfigAnnotationKey, node.Name)
}
parsedEgressIPConfig, err := parseNodeEgressIPConfig(&nodeEgressIPConfig[0])
if err != nil {
return nil, err
}
// ParsedNodeEgressIPConfiguration.V[4|6].IP is used to verify if an egress IP matches node IP to disable its creation
// use node IP instead of the value assigned from cloud egress CIDR config
nodeIfAddr, err := getNodeIfAddrAnnotation(node)
if err != nil {
return nil, err
}
if nodeIfAddr.IPv4 != "" {
ipv4, _, err := net.ParseCIDR(nodeIfAddr.IPv4)
if err != nil {
return nil, err
}
parsedEgressIPConfig.V4.IP = ipv4
}
if nodeIfAddr.IPv6 != "" {
ipv6, _, err := net.ParseCIDR(nodeIfAddr.IPv6)
if err != nil {
return nil, err
}
parsedEgressIPConfig.V6.IP = ipv6
}
return parsedEgressIPConfig, nil
}
func parseNodeEgressIPConfig(egressIPConfig *nodeEgressIPConfiguration) (*ParsedNodeEgressIPConfiguration, error) {
parsedEgressIPConfig := &ParsedNodeEgressIPConfiguration{
Capacity: egressIPConfig.Capacity,
}
if egressIPConfig.IFAddr.IPv4 != "" {
ipv4, v4Subnet, err := net.ParseCIDR(egressIPConfig.IFAddr.IPv4)
if err != nil {
return nil, err
}
parsedEgressIPConfig.V4 = ParsedIFAddr{
IP: ipv4,
Net: v4Subnet,
}
}
if egressIPConfig.IFAddr.IPv6 != "" {
ipv6, v6Subnet, err := net.ParseCIDR(egressIPConfig.IFAddr.IPv6)
if err != nil {
return nil, err
}
parsedEgressIPConfig.V6 = ParsedIFAddr{
IP: ipv6,
Net: v6Subnet,
}
}
return parsedEgressIPConfig, nil
}
// GetNodeEgressLabel returns label annotation needed for marking nodes as egress assignable
func GetNodeEgressLabel() string {
return ovnNodeEgressLabel
}
func SetNodeHostAddresses(nodeAnnotator kube.Annotator, addresses sets.Set[string]) error {
return nodeAnnotator.Set(ovnNodeHostAddresses, addresses.UnsortedList())
}
// ParseNodeHostAddresses returns the parsed host addresses living on a node
func ParseNodeHostAddresses(node *kapi.Node) (sets.Set[string], error) {
addrAnnotation, ok := node.Annotations[ovnNodeHostAddresses]
if !ok {
return nil, newAnnotationNotSetError("%s annotation not found for node %q", ovnNodeHostAddresses, node.Name)
}
var cfg []string
if err := json.Unmarshal([]byte(addrAnnotation), &cfg); err != nil {
return nil, fmt.Errorf("failed to unmarshal host addresses annotation %s for node %q: %v",
addrAnnotation, node.Name, err)
}
return sets.New(cfg...), nil
}