From 13fc6f0ceafd61b22bcf50d3fe095fbb63caccf4 Mon Sep 17 00:00:00 2001 From: Jaeryn Date: Fri, 6 Jul 2018 08:14:15 -0700 Subject: [PATCH 1/2] Adding check to prevent AzureNetworkContainer.exe from running if nc exists and the version has not changed. --- cns/restserver/restserver.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cns/restserver/restserver.go b/cns/restserver/restserver.go index 542e5dfe99..a08ef43e9e 100644 --- a/cns/restserver/restserver.go +++ b/cns/restserver/restserver.go @@ -915,13 +915,22 @@ func (service *httpRestService) createOrUpdateNetworkContainer(w http.ResponseWr switch r.Method { case "POST": if req.NetworkContainerType == cns.WebApps { + // try to get the saved nc state if it exists + service.lock.Lock() + existing, ok := service.state.ContainerStatus[req.NetworkContainerid] + service.lock.Unlock() nc := service.networkContainer - if err := nc.Create(req); err != nil { - returnMessage = fmt.Sprintf("[Azure CNS] Error. CreateOrUpdateNetworkContainer failed %v", err.Error()) - returnCode = UnexpectedError - break + + // create/update nc only if it doesn't exist or it exists and the requested version is different from the saved version + if !ok || (ok && existing.VMVersion != req.Version) { + if err = nc.Create(req); err != nil { + returnMessage = fmt.Sprintf("[Azure CNS] Error. CreateOrUpdateNetworkContainer failed %v", err.Error()) + returnCode = UnexpectedError + break + } } } + returnCode, returnMessage = service.saveNetworkContainerGoalState(req) default: From 66c7831f8da907025666fdbfdc688092a55d72c4 Mon Sep 17 00:00:00 2001 From: Jaeryn Date: Fri, 6 Jul 2018 15:46:36 -0700 Subject: [PATCH 2/2] Making changes as per Tamilmani. --- cns/restserver/restserver.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cns/restserver/restserver.go b/cns/restserver/restserver.go index a08ef43e9e..d52ecb8421 100644 --- a/cns/restserver/restserver.go +++ b/cns/restserver/restserver.go @@ -919,10 +919,10 @@ func (service *httpRestService) createOrUpdateNetworkContainer(w http.ResponseWr service.lock.Lock() existing, ok := service.state.ContainerStatus[req.NetworkContainerid] service.lock.Unlock() - nc := service.networkContainer // create/update nc only if it doesn't exist or it exists and the requested version is different from the saved version if !ok || (ok && existing.VMVersion != req.Version) { + nc := service.networkContainer if err = nc.Create(req); err != nil { returnMessage = fmt.Sprintf("[Azure CNS] Error. CreateOrUpdateNetworkContainer failed %v", err.Error()) returnCode = UnexpectedError @@ -976,6 +976,9 @@ func (service *httpRestService) getNetworkContainerResponse(req cns.GetNetworkCo var containerID string var getNetworkContainerResponse cns.GetNetworkContainerResponse + service.lock.Lock() + defer service.lock.Unlock() + switch service.state.OrchestratorType { case cns.Kubernetes: var podInfo cns.KubernetesPodInfo @@ -1058,7 +1061,11 @@ func (service *httpRestService) deleteNetworkContainer(w http.ResponseWriter, r var containerStatus containerstatus var ok bool - if containerStatus, ok = service.state.ContainerStatus[req.NetworkContainerid]; !ok { + service.lock.Lock() + containerStatus, ok = service.state.ContainerStatus[req.NetworkContainerid] + service.lock.Unlock() + + if !ok { log.Printf("Not able to retrieve network container details for this container id %v", req.NetworkContainerid) break }