Skip to content

Commit 9a7db2c

Browse files
author
Jing Zhang
committed
Add comments in nodeAddresses()
Signed-off-by: Jing Zhang <[email protected]>
1 parent afc478a commit 9a7db2c

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

pkg/openstack/instances.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,32 @@ func nodeAddresses(srv *servers.Server, interfaces []attachinterfaces.Interface,
640640
return nil, err
641641
}
642642

643-
// Add subports as if they are directly attached
644-
klog.V(5).Infof("Node '%s' is directly attached to %d networks '%s'", srv.Name, len(addresses), addresses)
645-
klog.V(5).Infof("Node '%s' is attached to %d networks '%s'", srv.Name, len(allPrivates), allPrivates)
643+
// Get the private networks that are not directly connected
646644
if len(addresses) < len(allPrivates) {
645+
extraPrivates := make(map[string][]Address)
646+
// For each private network
647647
for k, v := range allPrivates {
648+
ok := false
649+
// For each address in the private network
650+
for _, a := range v {
651+
// Check if the address is directly connected
652+
for _, v1 := range addresses {
653+
for _, a1 := range v1 {
654+
if a.Addr == a1.Addr {
655+
ok = true
656+
break
657+
}
658+
}
659+
}
660+
}
661+
// All the addresses in the private network are not directly connected
662+
// Save the private network
663+
if !ok {
664+
extraPrivates[k] = v
665+
}
666+
}
667+
klog.V(5).Infof("Node '%s' extraPrivates '%s'", srv.Name, extraPrivates)
668+
for k, v := range extraPrivates {
648669
v1, ok := addresses[k]
649670
if !ok {
650671
addresses[k] = v
@@ -777,7 +798,7 @@ func getSubInterfaces(interfaces []attachinterfaces.Interface, network *gophercl
777798
}
778799
}
779800
}
780-
klog.V(5).Infof("Node has %d subports '%v'", len(subports), subports)
801+
klog.V(5).Infof("Node has %d sub-interfaces '%v'", len(subports), subports)
781802
return subports, nil
782803
}
783804

pkg/openstack/openstack_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,22 +1003,6 @@ func TestNodeAddressesWithSubports(t *testing.T) {
10031003
NetID: "59c2e3cc-26a2-44c8-b8dc-d10f3995bcd9",
10041004
MACAddr: "fa:16:3e:36:b7:8c",
10051005
},
1006-
{
1007-
PortState: "ACTIVE",
1008-
FixedIPs: []attachinterfaces.FixedIP{
1009-
{
1010-
SubnetID: "b1c1f54e-f7cc-474f-be4c-f559ffb7fc94",
1011-
IPAddress: "14.14.14.98",
1012-
},
1013-
{
1014-
SubnetID: "3d3ab7f7-e235-4476-81a2-62982f9f9673",
1015-
IPAddress: "3000:0:0:1::39d",
1016-
},
1017-
},
1018-
PortID: "a9145a03-1c58-442e-8ca5-cf85a65fdae4",
1019-
NetID: "59c2e3cc-26a2-44c8-b8dc-d10f3995bcd9",
1020-
MACAddr: "fa:16:3e:36:b7:8c",
1021-
},
10221006
{
10231007
PortState: "ACTIVE",
10241008
FixedIPs: []attachinterfaces.FixedIP{

0 commit comments

Comments
 (0)