Skip to content

Commit 50685cf

Browse files
author
Jing Zhang
committed
Take care of two code comments:
(1) Port list to get trunk details (2) Back out feature action flag trunk-support-enabled
1 parent 6f63f5f commit 50685cf

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

pkg/openstack/instances.go

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"k8s.io/cloud-provider-openstack/pkg/util"
4646
"k8s.io/cloud-provider-openstack/pkg/util/errors"
4747
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
48-
"k8s.io/cloud-provider-openstack/pkg/util/openstack"
4948
)
5049

5150
// Instances encapsulates an implementation of Instances for OpenStack.
@@ -641,9 +640,9 @@ func nodeAddresses(srv *servers.Server, ports []ports.Port, networkingOpts Netwo
641640
}
642641

643642
// Add the private addresses that are not directly connected
644-
if len(addresses) < len(allPrivates) && networkingOpts.TrunkSupportEnabled {
643+
if len(addresses) < len(allPrivates) {
645644
numExtraPrivates := addExtraNodeAddresses(addresses, allPrivates)
646-
klog.V(5).Infof("Node '%s' is added %d extra private interfaces '%s'", srv.Name, numExtraPrivates, addresses)
645+
klog.V(5).Infof("Node '%s' is added %d extra private interfaces", srv.Name, numExtraPrivates)
647646
}
648647

649648
var networks []string
@@ -754,56 +753,47 @@ func getAttachedPorts(client *gophercloud.ServiceClient, networkingOpts Networki
754753
DeviceOwner: "compute:nova",
755754
}
756755

757-
interfaces, err := openstack.GetPorts(client, listOpts)
756+
type portWithTrunkDetails struct {
757+
ports.Port
758+
trunk_details.TrunkDetailsExt
759+
}
760+
761+
var interfaces []ports.Port
762+
var allPorts []portWithTrunkDetails
763+
764+
allPages, err := ports.List(client, listOpts).AllPages()
758765
if err != nil {
759766
return interfaces, err
760767
}
761-
if networkingOpts.TrunkSupportEnabled {
762-
subInterfaces, err := getSubInterfaces(client, interfaces)
763-
if err != nil {
764-
return interfaces, err
765-
}
766-
interfaces = append(interfaces, subInterfaces...)
768+
err = ports.ExtractPortsInto(allPages, &allPorts)
769+
if err != nil {
770+
return interfaces, err
767771
}
768772

769-
return interfaces, nil
770-
}
771-
772-
// getSubInterfaces returns the sub-interfaces attached via trunks to the specified interfaces
773-
func getSubInterfaces(client *gophercloud.ServiceClient, interfaces []ports.Port) ([]ports.Port, error) {
774-
var subports []ports.Port
775-
var portExt struct {
776-
ports.Port
777-
trunk_details.TrunkDetailsExt
778-
}
779-
for _, iface := range interfaces {
780-
// Check if trunk is attached to the interface
781-
err := ports.Get(client, iface.ID).ExtractInto(&portExt)
782-
if err != nil {
783-
klog.Errorf("Failed to get port %s trunk_details: %v", iface.ID, err)
784-
return subports, nil
785-
}
773+
for _, portExt := range allPorts {
774+
interfaces = append(interfaces, portExt.Port)
775+
// Check if trunk is attached to the port
786776
if portExt.TrunkDetails.TrunkID == "" {
787777
continue
788778
}
789-
// Get subports attached to the trunk
779+
// Get subport addresses
790780
for _, subport := range portExt.TrunkDetails.SubPorts {
791781
p, err := ports.Get(client, subport.PortID).Extract()
792782
if err != nil {
793783
klog.Errorf("Failed to get subport %s details: %v", subport.PortID, err)
794-
return subports, nil
784+
continue
795785
}
796786
n, err := networks.Get(client, p.NetworkID).Extract()
797787
if err != nil {
798788
klog.Errorf("Failed to get subport %s network details: %v", subport.PortID, err)
799-
return subports, nil
789+
continue
800790
}
801791
p.Status = "ACTIVE"
802792
p.NetworkID = n.Name
803-
subports = append(subports, *p)
793+
interfaces = append(interfaces, *p)
804794
}
805-
klog.V(5).Infof("Node interface %s has %d sub-interfaces '%v'", iface.Name, len(subports), subports)
806-
807795
}
808-
return subports, nil
796+
797+
klog.V(5).Infof("Node %s has %d interfaces '%v'", serverID, len(interfaces), interfaces)
798+
return interfaces, nil
809799
}

0 commit comments

Comments
 (0)