-
Notifications
You must be signed in to change notification settings - Fork 260
Update CNS to handle updated DNC API in managed mode #725
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
Update CNS to handle updated DNC API in managed mode #725
Conversation
Codecov Report
@@ Coverage Diff @@
## master #725 +/- ##
==========================================
+ Coverage 38.93% 39.03% +0.09%
==========================================
Files 83 83
Lines 10697 10683 -14
==========================================
+ Hits 4165 4170 +5
+ Misses 6034 6006 -28
- Partials 498 507 +9 |
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.
Couple comments
| if sleep { | ||
| time.Sleep(acn.FiveSeconds) | ||
| } | ||
| } |
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 understand that this is code that was moved, but perhaps it's a good chance to clean it up since it is a bit hard to follow. My main recommendation would be to extract the body of the loop to a function such as:
func registerNode(httpCl *http.Client, url string, body io.Reader) (cns.SetOrchestratorTypeRequest, error) {
response, err := httpCl.Post(url, acn.JsonContent, body)
if err != nil {...}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {...}
var req cns.SetOrchestratorTypeRequest
_ = json.NewDecoder(response.Body).Decode(&req)
return req, nil
}which then makes the loop much simpler:
for {
req, err := registerNode(httpc, registerNodeURL, &body)
if err != nil {
logger.Errorf(err.Error())
time.Sleep(acn.FiveSeconds)
continue
}
httpRestService.SetNodeOrchestrator(&req)
break
}To go a step further, I would consider making a proper DNCClient struct, which embeds reusable dependencies such as an http client. The main benefit of this is that the calling code can then use an interface and stub out the actual implementation when writing tests. That can be a later refactor though. See cnsclient in the dnc repo as an example.
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.
Thanks, I have updated the logic. I will create the DNCClient struct as a part of next PR where I'll handle the msi in the dncclient.
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 refactored this section in #680 , along with Ramiro's suggestion, i added ticker logic too
| response.Body.Close() | ||
| } | ||
|
|
||
| return nodeInfoResponse, 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.
prefer to return early. it's easier then to read the happy path of the code without much indentation.
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
|
This pull request is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days |
|
Pull request closed due to inactivity. |
fix: Update CNS to handle updated DNC API in managed mode
This change updates CNS code to consume the updated DNC API urls for RegisterNode and
SyncNodeNcStatus. This change also refactors the calls to DNC in dncclient package.