-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to Policy API for Segment and Segment Ports #260
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks good, I have some nits and suggestions inline.
pkg/types/utils.go
Outdated
converter := bindings.NewTypeConverter() | ||
obj, errs := converter.ConvertToGolang(dataValue, destBindingType) | ||
if len(errs) > 0 { | ||
t, _ := obj.(T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any need for assigning t
here? I think you can probably just return nil, errs[0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't return nil as per the compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I found a better way to do this
cachedNodeSet[nodeName] = &statusmanager.NodeStatus{ | ||
Addresses: nodeAddresses, | ||
Success: false, | ||
Reason: fmt.Sprintf("Error while achieving port with specific address for node %s: %v", nodeName, err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this error message has been like this for year, do you mind improving it?
It goes into the node status and not just in the logs.
Maybe just use "retrieving" instead of "achieving" (and do this for all the place where we ser this error in status)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if inSlice(address, nodeAddresses) && !inSlice(address, collectedAddresses) { | ||
log.Info(fmt.Sprintf("Node address %s matches port %s", address, port.Id)) | ||
log.Info(fmt.Sprintf("Node address %s matches port %s", address, *port.Id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: change this line to node address %s matches segment port %s
.
In this way, when we will check logs for troubleshooting, we will know that the operator is executing the code for policy API.
Also, I think the linter suggests to start log lines with a lowercase letter, so it might be another good thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
portState, err := segPortStateClient.Get(segId, *port.Id, nil, nil) | ||
if err != nil { | ||
return filteredPorts, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this check and the one at line 210 I'm thinking that perhaps we want to do thing a little differently:
Instead of returning at the first error, keep iterating over ports, and then return slices for FilteredPorts and errors.
The thing is that we want to find "the" port with the right IP, so even if we encounter issues while fetching or parsing state for other ports, we might still be able to find the port we are looking for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we do this only if there was only 1 Segment Port for the node? From the code, we can expect multiple Segment Ports matching the same IP. If that's the case, we'll end up doing partial update which may actually go unnoticed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what we can do alternatively is finish the loop collecting errors. If there are any ports which couldn't be read from NSX, we return 1 error providing the info of all erroneous ports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!
As NSX 9.0 intends to remove MP APIs, we need to switch to Policy API. This patch makes the changes necessary for node controller Logical Switch related APIs The patch removes some stale code which is no longer used Testing Done ------------ - Verified that the Segment Ports for nodes are updated by the operator - Verified that the operator is running fine Jira: NCP-601
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
portState, err := segPortStateClient.Get(segId, *port.Id, nil, nil) | ||
if err != nil { | ||
return filteredPorts, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove using SDK:
nsxt "github.com/vmware/go-vmware-nsxt"
So, we should not use nsx manger client at code line#L106
ManagerClient *nsxt.APIClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey Yun, the change you suggest is doable but I am not sure if it matches the criteria for this patch as the intention here is to switch those MP api calls to Policy api calls which are going to be removed. The suggested change switches the sdk but still uses mp api and these api calls are not planned for removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to use some inventory API but they are supported as well to list vif and vms
Here, we can use this client from sdk:
At code line#L124
vms, _, err := nsxClient.FabricApi.ListVirtualMachines
we can use vm client from sdk:
https://github.com/vmware/vsphere-automation-sdk-go/blob/services/nsxt/v0.12.0/services/nsxt-mp/nsx/fabric/VirtualMachinesClient.go
At code line#L151
vifs, _, err := nsxClient.FabricApi.ListVifs(nsxClient.Context, localVarOptionals)
we can use vif licent from sdk
https://github.com/vmware/vsphere-automation-sdk-go/blob/services/nsxt/v0.12.0/services/nsxt-mp/nsx/fabric/VifsClient.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
As NSX 9.0 intends to remove MP APIs, we need to switch to Policy API. This patch makes the changes necessary for node controller Logical Switch related APIs
The patch removes some stale code which is no longer used
Testing Done
Jira: NCP-601