Skip to content

Commit aafc041

Browse files
committed
Addressing comments
1 parent 2129a6f commit aafc041

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

cns/nmagentclient/nmagentclient.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ func GetNmAgentSupportedApis(
125125
logger.Errorf("[Azure-CNS] %s", returnErr)
126126
return nil, returnErr
127127
}
128+
defer response.Body.Close()
129+
128130
if response.StatusCode != http.StatusOK {
129131
returnErr = fmt.Errorf(
130132
"Failed to retrieve Supported Apis from NMAgent with StatusCode: %d",

cns/service/main.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ func registerNode(httpc *http.Client, httpRestService cns.HTTPService, dncEP, in
278278
responseChan := make(chan error)
279279

280280
for {
281+
sendRegisterNodeRequest(httpc, httpRestService, nodeRegisterRequest, url, responseChan)
281282
select {
282283
case responseErr := <-responseChan:
283284
return responseErr
284285
case <-nodeRegisterTicker.C:
285-
go sendRegisterNodeRequest(httpc, httpRestService, nodeRegisterRequest, url, responseChan)
286+
continue
286287
}
287288
}
288289
}
@@ -309,29 +310,30 @@ func sendRegisterNodeRequest(
309310
}
310311

311312
response, err = httpc.Post(registerURL, "application/json", &body)
312-
if err == nil {
313-
if response.StatusCode == http.StatusCreated {
314-
var req cns.SetOrchestratorTypeRequest
315-
decodeErr := json.NewDecoder(response.Body).Decode(&req)
316-
if decodeErr != nil {
317-
log.Errorf("decoding Node Resgister response json failed with %v", err)
318-
responseChan <- err
319-
return
320-
}
321-
httpRestService.SetNodeOrchestrator(&req)
313+
if err != nil {
314+
logger.Errorf("[Azure CNS] Failed to register node with err: %+v", err)
315+
return
316+
}
317+
defer response.Body.Close()
322318

323-
logger.Printf("[Azure CNS] Node Registered")
324-
responseChan <- nil
325-
} else {
326-
err = fmt.Errorf("[Azure CNS] Failed to register node with http status code %s", strconv.Itoa(response.StatusCode))
327-
logger.Errorf(err.Error())
328-
responseChan <- err
329-
}
319+
if response.StatusCode != http.StatusCreated {
320+
err = fmt.Errorf("[Azure CNS] Failed to register node with http status code %s", strconv.Itoa(response.StatusCode))
321+
logger.Errorf(err.Error())
322+
responseChan <- err
323+
return
324+
}
330325

331-
response.Body.Close()
332-
} else {
333-
logger.Errorf("[Azure CNS] Failed to register node with err: %+v", err)
326+
var req cns.SetOrchestratorTypeRequest
327+
decodeErr := json.NewDecoder(response.Body).Decode(&req)
328+
if decodeErr != nil {
329+
log.Errorf("decoding Node Resgister response json failed with %v", err)
330+
responseChan <- err
331+
return
334332
}
333+
httpRestService.SetNodeOrchestrator(&req)
334+
335+
logger.Printf("[Azure CNS] Node Registered")
336+
responseChan <- nil
335337
}
336338

337339
// Main is the entry point for CNS.

0 commit comments

Comments
 (0)