-
Notifications
You must be signed in to change notification settings - Fork 260
Add nc version in SecondaryIPConfig stucture. #701
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #701 +/- ##
==========================================
- Coverage 38.84% 38.61% -0.24%
==========================================
Files 79 79
Lines 10471 10479 +8
==========================================
- Hits 4067 4046 -21
- Misses 5912 5938 +26
- Partials 492 495 +3 |
|
There is no change in the reconcile funntion? can you also cover it here? That will complete the NC version check for all scenarios . |
Discussed offline. We'll use a separate PR to address this scenario. |
ramiro-gamarra
left a comment
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.
Some comments
| ipSubnet.PrefixLength = uint8(size) | ||
| ncRequest.IPConfiguration.IPSubnet = ipSubnet | ||
| ncRequest.IPConfiguration.GatewayIPAddress = nc.DefaultGateway | ||
| ncVersion, _ := strconv.Atoi(ncRequest.Version) |
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.
should probably bubble the error to be safe
cns/restserver/internalapi_test.go
Outdated
| } | ||
|
|
||
| func validateSecondaryIPsNCVersion(t *testing.T, req cns.CreateNetworkContainerRequest) { | ||
| containerStatus := svc.state.ContainerStatus[req.NetworkContainerid] |
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.
Couple of things:
- Reading
stateshould be mutex guarded - You should also check that the map actually contains an entry for the nc 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.
- This is a validation code in test file. I don't think mutex guard is necessary. No others have access to svc.state.
- Not necessary. If it doesn't exist, test will fail.
cns/restserver/internalapi_test.go
Outdated
| if (secIPConfig.IPAddress == "10.0.0.16" && secIPConfig.NCVersion != 0) || | ||
| (secIPConfig.IPAddress == "10.0.0.17" && secIPConfig.NCVersion != 1) { | ||
| t.Fatalf("nc request version is %d, secondary ip %s nc version is %d, expected nc version is 0", | ||
| ncVersion, secIPConfig.IPAddress, secIPConfig.NCVersion) |
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.
These assertion values (the expected ip addresses and versions) are very far from the test. If you need to create similar tests with different IP addresses, this would not be very reusable. You should define the expected values on the test, and pass them to this function. The check is also very narrow: if there was only a secondary IP of 10.0.0.15 for example, this would pass.
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.
No. This test is designed specifically and is validating specific scenario.
In this specific test, secondary IP address only contains 10.0.0.16 and 10.0.0.17.
10.0.0.16 must be version 0 and 10.0.0.17 must be version 1.
cns/restserver/util.go
Outdated
| for ipId, ipconfig := range ipconfigs { | ||
| // New secondary IP configs has new NC version however, CNS don't want to override existing IPs'with new NC version | ||
| // Set it back to previous NC version if IP already exist. | ||
| if existingIPConfig, existsInPreviousIPConfig := existingSecondaryIPConfigs[ipId]; existsInPreviousIPConfig && existingIPConfig.IPAddress == ipconfig.IPAddress { |
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 the check on ip address equality necessary?
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 it's necessary. If uuid is the same, IPAddress must be same. If not the same, then sth wrong. At least we don't want to set the NC version back.
In other way, I don't see any drawback to double check IPAddress.
cns/restserver/internalapi_test.go
Outdated
| } | ||
|
|
||
| func validateSecondaryIPsNCVersion(t *testing.T, req cns.CreateNetworkContainerRequest) { | ||
| containerStatus := svc.state.ContainerStatus[req.NetworkContainerid] |
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.
This function seems generic but inside it has hardcoded the ipaddress and expected version. Can we pass the expected SecondaryIpConfig as parameter and compare the req with expected list? This will allow to reuse this function in future as well
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 can but I don't think it's necessary. I don't think any other test should reuse this function. This validation is designed for TestCreateAndUpdateNCWithSecondaryIPNCVersion specifically.
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 moved this validation to test function and avoid confusion.
ramiro-gamarra
left a comment
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.
Few more comments
cns/restserver/internalapi_test.go
Outdated
| req := createNCReqInternal(t, secondaryIPConfigs, ncID, strconv.Itoa(ncVersion)) | ||
| containerStatus := svc.state.ContainerStatus[req.NetworkContainerid] | ||
| // Validate secondary IPs' NC version has been updated by NC request | ||
| receivedSecondaryIPConfigs = containerStatus.CreateNetworkContainerRequest.SecondaryIPConfigs |
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.
- no need to make a map in line 59, just use
:=here - the reason why a check for existence of entry in the map is better is that the test won't fail if there is no match. If you don't get the check for existence, you get the zero value of a struct, including all of it's members recursively, and ranging over a nil map is valid. In case the nc id was not found in the map, the checks below will not happen, and the test will continue as normal. Let me know if that makes sense.
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 what you are trying to say is adding one more check in map length. I can do that though it's not the key point in this test.
cns/restserver/internalapi_test.go
Outdated
| // Though "10.0.0.16" IP exists in NC version 1, secodanry IP still keep its original NC version 0 | ||
| if (secIPConfig.IPAddress == "10.0.0.16" && secIPConfig.NCVersion != 0) || | ||
| (secIPConfig.IPAddress == "10.0.0.17" && secIPConfig.NCVersion != 1) { | ||
| t.Fatalf("nc request version is %d, secondary ip %s nc version is %d, expected nc version is 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.
prefer a switch statement here, and messages more specific to each. in case the inconsistent version was with 10.0.0.17, the message still tells you that it expected 0, which is not appropriate:
switch secIPConfig:
case "10.0.0.16":
// check for 0
case "10.0.0.17":
// check for 1
default:
// error since this is unexpectedDiscussed offline, it's ready to merge.
feat: Add NC version in SecondaryIPConfig structure.
Reason for Change:
When CNS reconcile, it needs NC version to determine whether an IP should be stay in pending programming or available.