Skip to content

Commit 5e85f71

Browse files
committed
Search node address in port's DiscoveredBindings instead RealizedBindings
In IPI + NSX-T impactor ufo, the node LSP's addresses are in discovered_bindings instead of realized_bindings. In previous NSX-T, the addresses locate in both realized_bindings and discovered_bindings, so we don't need to worry about the upgrade case. This patch also will remove some stale functions.
1 parent 77de513 commit 5e85f71

1 file changed

Lines changed: 4 additions & 70 deletions

File tree

pkg/controller/node/node_controller.go

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ import (
2424
"github.com/vmware/nsx-container-plugin-operator/pkg/controller/statusmanager"
2525
operatortypes "github.com/vmware/nsx-container-plugin-operator/pkg/types"
2626
"github.com/vmware/vsphere-automation-sdk-go/runtime/core"
27-
"github.com/vmware/vsphere-automation-sdk-go/runtime/data"
2827
vspherelog "github.com/vmware/vsphere-automation-sdk-go/runtime/log"
2928
policyclient "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client"
3029
"github.com/vmware/vsphere-automation-sdk-go/runtime/security"
31-
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
32-
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/search"
3330
"gopkg.in/ini.v1"
3431
corev1 "k8s.io/api/core/v1"
3532
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -196,15 +193,15 @@ func filterPortsByNodeAddresses(nsxClients *NsxClients, ports *[]nsxtmgr.Logical
196193
if err != nil {
197194
return filteredPorts, err
198195
}
199-
if len(logicalPort.RealizedBindings) == 0 {
196+
if len(logicalPort.DiscoveredBindings) == 0 {
200197
continue
201198
}
202199
var collectedAddresses []string
203-
for _, realizedBinding := range logicalPort.RealizedBindings {
204-
address := realizedBinding.Binding.IpAddress
200+
for _, discoveredBinding := range logicalPort.DiscoveredBindings {
201+
address := discoveredBinding.Binding.IpAddress
205202
if inSlice(address, nodeAddresses) && !inSlice(address, collectedAddresses) {
206203
log.Info(fmt.Sprintf("Node address %s matches port %s", address, port.Id))
207-
// The addresses in logicalPort.RealizedBindings may be duplicate so we use collectedAddresses to ensure the uniqueness in filteredPorts.
204+
// The addresses in logicalPort.DiscoveredBindings may be duplicate so we use collectedAddresses to ensure the uniqueness in filteredPorts.
208205
collectedAddresses = append(collectedAddresses, address)
209206
filteredPorts = append(filteredPorts, &port)
210207
}
@@ -220,69 +217,6 @@ func filterPortsByNodeAddresses(nsxClients *NsxClients, ports *[]nsxtmgr.Logical
220217
return filteredPorts, err
221218
}
222219

223-
func searchNodePortByVcNameAddress(nsxClients *NsxClients, nodeName string, nodeAddress string) (*model.SegmentPort, error) {
224-
log.Info(fmt.Sprintf("Searching segment port for node %s", nodeName))
225-
connector := nsxClients.PolicyConnector
226-
searchClient := search.NewDefaultQueryClient(connector)
227-
// The format of node segment port display_name:
228-
// <vmx file's parent directory name>/<node vSphere name>.vmx@<tn-id>
229-
// The vmx file's parent directory name can include VM name or a uid string for a vSAN VM
230-
searchString := fmt.Sprintf("resource_type:SegmentPort AND display_name:*\\/%s.vmx*", nodeName)
231-
ports, err := searchClient.List(searchString, nil, nil, nil, nil, nil)
232-
if err != nil {
233-
return nil, err
234-
}
235-
if len(ports.Results) == 0 {
236-
return nil, errors.Errorf("segment port for node %s not found", nodeName)
237-
}
238-
portIndex := 0
239-
portIndex, err = filterSegmentPorts(nsxClients, ports.Results, nodeName, nodeAddress)
240-
if err != nil {
241-
return nil, errors.Errorf("found %d segment ports for node %s, but none with address %s: %s", len(ports.Results), nodeName, nodeAddress, err)
242-
}
243-
portId, err := ports.Results[portIndex].Field("id")
244-
if err != nil {
245-
return nil, err
246-
}
247-
portPath, err := ports.Results[portIndex].Field("parent_path")
248-
if err != nil {
249-
return nil, err
250-
}
251-
portIdValue := (portId).(*data.StringValue).Value()
252-
portPathValue := (portPath).(*data.StringValue).Value()
253-
segmentPort := model.SegmentPort{
254-
Id: &portIdValue,
255-
Path: &portPathValue,
256-
}
257-
return &segmentPort, nil
258-
}
259-
260-
func filterSegmentPorts(nsxClients *NsxClients, ports []*data.StructValue, nodeName string, nodeAddress string) (int, error) {
261-
log.Info(fmt.Sprintf("Found %d segment ports for node %s, checking addresses", len(ports), nodeName))
262-
for idx, port := range ports {
263-
portPolicyId, err := port.Field("id")
264-
if err != nil {
265-
return -1, err
266-
}
267-
portPolicyIdValue := (portPolicyId).(*data.StringValue).Value()
268-
// there's an assumption that the policy ID has format "default:<manager_id>"
269-
portMgrId := string([]byte(portPolicyIdValue)[8:])
270-
nsxClient := nsxClients.ManagerClient
271-
logicalPort, _, err := nsxClient.LogicalSwitchingApi.GetLogicalPortState(nsxClient.Context, portMgrId)
272-
if err != nil {
273-
return -1, err
274-
}
275-
if len(logicalPort.RealizedBindings) == 0 {
276-
continue
277-
}
278-
address := logicalPort.RealizedBindings[0].Binding.IpAddress
279-
if address == nodeAddress {
280-
return idx, nil
281-
}
282-
}
283-
return -1, errors.Errorf("no port matches")
284-
}
285-
286220
func getConnectorTLSConfig(insecure bool, clientCertFile string, clientKeyFile string, caFile string) (*tls.Config, error) {
287221
tlsConfig := tls.Config{InsecureSkipVerify: insecure}
288222

0 commit comments

Comments
 (0)