@@ -583,7 +583,7 @@ func nodeAddresses(srv *servers.Server, ports []ports.Port, networkingOpts Netwo
583
583
addrs := []v1.NodeAddress {}
584
584
585
585
// parse private IP addresses first in an ordered manner
586
- allPrivates := make (map [string ][]Address )
586
+ addressesByNetworkID := make (map [string ][]Address )
587
587
for _ , port := range ports {
588
588
for _ , fixedIP := range port .FixedIPs {
589
589
if port .Status == "ACTIVE" {
@@ -595,10 +595,8 @@ func nodeAddresses(srv *servers.Server, ports []ports.Port, networkingOpts Netwo
595
595
Address : fixedIP .IPAddress ,
596
596
},
597
597
)
598
- if port .NetworkID != "" {
599
- addr := Address {IPType : "fixed" , Addr : fixedIP .IPAddress }
600
- allPrivates [port .NetworkID ] = append (allPrivates [port .NetworkID ], addr )
601
- }
598
+ addr := Address {IPType : "fixed" , Addr : fixedIP .IPAddress }
599
+ addressesByNetworkID [port .NetworkID ] = append (addressesByNetworkID [port .NetworkID ], addr )
602
600
}
603
601
}
604
602
}
@@ -639,10 +637,11 @@ func nodeAddresses(srv *servers.Server, ports []ports.Port, networkingOpts Netwo
639
637
return nil , err
640
638
}
641
639
642
- // Add the private addresses that are not directly connected
643
- if len (addresses ) < len (allPrivates ) {
644
- numExtraPrivates := addExtraNodeAddresses (addresses , allPrivates )
645
- klog .V (5 ).Infof ("Node '%s' is added %d extra private interfaces" , srv .Name , numExtraPrivates )
640
+ // Add the addresses assigned on subports via trunk
641
+ // This adds the vlan networks to which subports are attached
642
+ if len (addresses ) < len (addressesByNetworkID ) {
643
+ nrSubportAddresses := addSubportNodeAddresses (addresses , addressesByNetworkID )
644
+ klog .V (5 ).Infof ("Node '%s' is added %d subport addresses" , srv .Name , nrSubportAddresses )
646
645
}
647
646
648
647
var networks []string
@@ -698,38 +697,40 @@ func nodeAddresses(srv *servers.Server, ports []ports.Port, networkingOpts Netwo
698
697
return addrs , nil
699
698
}
700
699
701
- // addExtraNodeAddresses addes addresses attached via trunk
702
- func addExtraNodeAddresses (addresses , allPrivates map [string ][]Address ) int {
703
- extraPrivates := make (map [string ][]Address )
704
- for network , interfaceAddresses := range allPrivates {
700
+ // addSubportNodeAddresses adds addresses assigned on subports
701
+ func addSubportNodeAddresses (addresses , addressesByNetworkID map [string ][]Address ) int {
702
+ subportAddresses := make (map [string ][]Address )
703
+ for network , portAddresses := range addressesByNetworkID {
705
704
found := false
706
- // For each address in the private network
707
- for _ , interfaceAddress := range interfaceAddresses {
708
- // Check if the address is directly assigned
705
+ for _ , portAddress := range portAddresses {
706
+ // Check if the address is directly attached to the node
709
707
for _ , nodeAddresses := range addresses {
710
708
for _ , nodeAddress := range nodeAddresses {
711
- if interfaceAddress .Addr == nodeAddress .Addr {
709
+ if portAddress .Addr == nodeAddress .Addr {
712
710
found = true
713
711
break
714
712
}
715
713
}
716
714
}
717
715
}
718
- // All the addresses in the private network are not directly assigned
719
- // Save the private network
716
+ // All the addresses in the vlan network are not directly attached to the node
717
+ // Save the vlan network
720
718
if ! found {
721
- extraPrivates [network ] = interfaceAddresses
719
+ subportAddresses [network ] = portAddresses
722
720
}
723
721
}
724
- for network , interfaceAddresses := range extraPrivates {
722
+ // add subport addresses to the node addresses
723
+ for network , portAddresses := range subportAddresses {
725
724
srvAddresses , ok := addresses [network ]
726
725
if ! ok {
727
- addresses [network ] = interfaceAddresses
726
+ addresses [network ] = portAddresses
728
727
} else {
729
- addresses [network ] = append (srvAddresses , interfaceAddresses ... )
728
+ // this is to take care the corner case
729
+ // where the same network is attached to the node both directly and via trunk
730
+ addresses [network ] = append (srvAddresses , portAddresses ... )
730
731
}
731
732
}
732
- return len (extraPrivates )
733
+ return len (subportAddresses )
733
734
}
734
735
735
736
func getAddressesByName (client * gophercloud.ServiceClient , name types.NodeName , networkingOpts NetworkingOpts ) ([]v1.NodeAddress , error ) {
@@ -758,24 +759,20 @@ func getAttachedPorts(client *gophercloud.ServiceClient, serverID string) ([]por
758
759
trunk_details.TrunkDetailsExt
759
760
}
760
761
761
- var interfaces []ports.Port
762
- var allPorts []portWithTrunkDetails
762
+ var allPorts []ports.Port
763
+ var allPortDetails []portWithTrunkDetails
763
764
764
765
allPages , err := ports .List (client , listOpts ).AllPages ()
765
766
if err != nil {
766
- return interfaces , err
767
+ return allPorts , err
767
768
}
768
- err = ports .ExtractPortsInto (allPages , & allPorts )
769
+ err = ports .ExtractPortsInto (allPages , & allPortDetails )
769
770
if err != nil {
770
- return interfaces , err
771
+ return allPorts , err
771
772
}
772
773
773
- for _ , portExt := range allPorts {
774
- interfaces = append (interfaces , portExt .Port )
775
- // Check if trunk is attached to the port
776
- if portExt .TrunkDetails .TrunkID == "" {
777
- continue
778
- }
774
+ for _ , portExt := range allPortDetails {
775
+ allPorts = append (allPorts , portExt .Port )
779
776
// Get subport addresses
780
777
for _ , subport := range portExt .TrunkDetails .SubPorts {
781
778
p , err := ports .Get (client , subport .PortID ).Extract ()
@@ -790,10 +787,10 @@ func getAttachedPorts(client *gophercloud.ServiceClient, serverID string) ([]por
790
787
}
791
788
p .Status = "ACTIVE"
792
789
p .NetworkID = n .Name
793
- interfaces = append (interfaces , * p )
790
+ allPorts = append (allPorts , * p )
794
791
}
795
792
}
796
793
797
- klog .V (5 ).Infof ("Node %s has %d interfaces '%v'" , serverID , len (interfaces ), interfaces )
798
- return interfaces , nil
794
+ klog .V (5 ).Infof ("Node %s has %d ports '%v'" , serverID , len (allPorts ), allPorts )
795
+ return allPorts , nil
799
796
}
0 commit comments