Skip to content

Commit 5349b69

Browse files
committed
Update stringifying configs
1 parent f0083cf commit 5349b69

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

pkg/bgp/peer_config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ import (
1515
type PeerConfig struct {
1616
LocalIP *string `yaml:"localip"`
1717
Password *utils.Base64String `yaml:"password"`
18-
Port *uint32 `yaml:"port"`
18+
Port uint32 `yaml:"port"`
1919
RemoteASN *uint32 `yaml:"remoteasn"`
2020
RemoteIP *net.IP `yaml:"remoteip"`
2121
}
2222

2323
// Custom Stringer to prevent leaking passwords when printed
2424
func (p PeerConfig) String() string {
2525
var fields []string
26+
fields = append(fields, fmt.Sprintf("Port: %d", p.Port))
2627

2728
if p.LocalIP != nil {
2829
fields = append(fields, fmt.Sprintf("LocalIP: %s", *p.LocalIP))
2930
}
30-
if p.Port != nil {
31-
fields = append(fields, fmt.Sprintf("Port: %d", *p.Port))
32-
}
3331
if p.RemoteASN != nil {
3432
fields = append(fields, fmt.Sprintf("RemoteASN: %d", *p.RemoteASN))
3533
}
@@ -43,7 +41,7 @@ func (p *PeerConfig) UnmarshalYAML(raw []byte) error {
4341
tmp := struct {
4442
LocalIP *string `yaml:"localip"`
4543
Password *utils.Base64String `yaml:"password"`
46-
Port *uint32 `yaml:"port"`
44+
Port uint32 `yaml:"port"`
4745
RemoteASN *uint32 `yaml:"remoteasn"`
4846
RemoteIP string `yaml:"remoteip"`
4947
}{}
@@ -93,9 +91,7 @@ func (p PeerConfigs) Passwords() []string {
9391
func (p PeerConfigs) Ports() []uint32 {
9492
ports := make([]uint32, 0)
9593
for _, cfg := range p {
96-
if cfg.Port != nil {
97-
ports = append(ports, *cfg.Port)
98-
}
94+
ports = append(ports, cfg.Port)
9995
}
10096
return ports
10197
}
@@ -176,7 +172,7 @@ func NewPeerConfigs(
176172
peerCfgs[i].RemoteASN = &remoteASNs[i]
177173

178174
if len(ports) != 0 {
179-
peerCfgs[i].Port = &ports[i]
175+
peerCfgs[i].Port = ports[i]
180176
}
181177

182178
if len(b64EncodedPasswords) != 0 {

pkg/bgp/peer_config_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ func TestPeerConfig_String(t *testing.T) {
1818
{
1919
name: "empty PeerConfig",
2020
config: PeerConfig{},
21-
expected: "PeerConfig{}",
21+
expected: "PeerConfig{Port: 0}",
2222
},
2323
{
2424
name: "LocalIP",
2525
config: PeerConfig{
2626
LocalIP: testutils.ValToPtr("192.168.1.1"),
2727
},
28-
expected: "PeerConfig{LocalIP: 192.168.1.1}",
28+
expected: "PeerConfig{Port: 0, LocalIP: 192.168.1.1}",
2929
},
3030
{
3131
name: "Port",
3232
config: PeerConfig{
33-
Port: testutils.ValToPtr(uint32(179)),
33+
Port: 179,
3434
},
3535
expected: "PeerConfig{Port: 179}",
3636
},
@@ -39,39 +39,39 @@ func TestPeerConfig_String(t *testing.T) {
3939
config: PeerConfig{
4040
RemoteASN: testutils.ValToPtr(uint32(65000)),
4141
},
42-
expected: "PeerConfig{RemoteASN: 65000}",
42+
expected: "PeerConfig{Port: 0, RemoteASN: 65000}",
4343
},
4444
{
4545
name: "RemoteIP",
4646
config: PeerConfig{
4747
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.1")),
4848
},
49-
expected: "PeerConfig{RemoteIP: 10.0.0.1}",
49+
expected: "PeerConfig{Port: 0, RemoteIP: 10.0.0.1}",
5050
},
5151
{
5252
name: "RemoteIP with IPv6",
5353
config: PeerConfig{
5454
RemoteIP: testutils.ValToPtr(net.ParseIP("2001:db8::1")),
5555
},
56-
expected: "PeerConfig{RemoteIP: 2001:db8::1}",
56+
expected: "PeerConfig{Port: 0, RemoteIP: 2001:db8::1}",
5757
},
5858
{
5959
name: "Password - should not be printed",
6060
config: PeerConfig{
6161
Password: testutils.ValToPtr(utils.Base64String("password")),
6262
},
63-
expected: "PeerConfig{}",
63+
expected: "PeerConfig{Port: 0}",
6464
},
6565
{
6666
name: "all fields - Password should not be printed",
6767
config: PeerConfig{
6868
LocalIP: testutils.ValToPtr("192.168.1.1"),
6969
Password: testutils.ValToPtr(utils.Base64String("password")),
70-
Port: testutils.ValToPtr(uint32(179)),
70+
Port: 179,
7171
RemoteASN: testutils.ValToPtr(uint32(65000)),
7272
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.1")),
7373
},
74-
expected: "PeerConfig{LocalIP: 192.168.1.1, Port: 179, RemoteASN: 65000, RemoteIP: 10.0.0.1}",
74+
expected: "PeerConfig{Port: 179, LocalIP: 192.168.1.1, RemoteASN: 65000, RemoteIP: 10.0.0.1}",
7575
},
7676
}
7777

@@ -100,12 +100,12 @@ func TestPeerConfigs_String(t *testing.T) {
100100
{
101101
LocalIP: testutils.ValToPtr("192.168.1.1"),
102102
Password: testutils.ValToPtr(utils.Base64String("secret")),
103-
Port: testutils.ValToPtr(uint32(179)),
103+
Port: 179,
104104
RemoteASN: testutils.ValToPtr(uint32(65000)),
105105
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.1")),
106106
},
107107
},
108-
expected: "PeerConfigs[PeerConfig{LocalIP: 192.168.1.1, Port: 179, RemoteASN: 65000, RemoteIP: 10.0.0.1}]",
108+
expected: "PeerConfigs[PeerConfig{Port: 179, LocalIP: 192.168.1.1, RemoteASN: 65000, RemoteIP: 10.0.0.1}]",
109109
},
110110
{
111111
name: "multiple PeerConfigs - passwords should not be printed",
@@ -117,15 +117,15 @@ func TestPeerConfigs_String(t *testing.T) {
117117
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.1")),
118118
},
119119
{
120-
Port: testutils.ValToPtr(uint32(1790)),
120+
Port: 179,
121121
RemoteASN: testutils.ValToPtr(uint32(65001)),
122122
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.2")),
123123
},
124124
{
125125
RemoteIP: testutils.ValToPtr(net.ParseIP("10.0.0.3")),
126126
},
127127
},
128-
expected: "PeerConfigs[PeerConfig{LocalIP: 192.168.1.1, RemoteASN: 65000, RemoteIP: 10.0.0.1},PeerConfig{Port: 1790, RemoteASN: 65001, RemoteIP: 10.0.0.2},PeerConfig{RemoteIP: 10.0.0.3}]",
128+
expected: "PeerConfigs[PeerConfig{Port: 0, LocalIP: 192.168.1.1, RemoteASN: 65000, RemoteIP: 10.0.0.1},PeerConfig{Port: 179, RemoteASN: 65001, RemoteIP: 10.0.0.2},PeerConfig{Port: 0, RemoteIP: 10.0.0.3}]",
129129
},
130130
}
131131

pkg/controllers/routing/network_routes_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,6 @@ func bgpPeerConfigsFromIndividualAnnotations(nodeAnnotations map[string]string,
14691469
// Get Global Peer Router ASN configs
14701470
var ports []uint32
14711471
nodeBgpPeerPortsAnnotation, ok := nodeAnnotations[peerPortAnnotation]
1472-
// Default to default BGP port if port annotation is not found
14731472
if ok {
14741473
portStrings := stringToSlice(nodeBgpPeerPortsAnnotation, ",")
14751474
ports, err = stringSliceToUInt32(portStrings)

0 commit comments

Comments
 (0)