diff --git a/cns/restserver/restserver.go b/cns/restserver/restserver.go index 4dabf072a..6ce956a52 100644 --- a/cns/restserver/restserver.go +++ b/cns/restserver/restserver.go @@ -113,6 +113,7 @@ func NewHTTPRestService(config *common.ServiceConfig) (HTTPService, error) { serviceState := &httpRestServiceState{} serviceState.Networks = make(map[string]*networkInfo) + serviceState.joinedNetworks = make(map[string]struct{}) return &HTTPRestService{ Service: service, @@ -124,7 +125,6 @@ func NewHTTPRestService(config *common.ServiceConfig) (HTTPService, error) { routingTable: routingTable, state: serviceState, }, nil - } // Start starts the CNS listener. @@ -980,10 +980,10 @@ func (service *HTTPRestService) setOrchestratorType(w http.ResponseWriter, r *ht log.Printf("[Azure CNS] setOrchestratorType") var ( - req cns.SetOrchestratorTypeRequest + req cns.SetOrchestratorTypeRequest returnMessage string - returnCode int - nodeID string + returnCode int + nodeID string ) err := service.Listener.Decode(w, r, &req) @@ -1757,10 +1757,6 @@ func (service *HTTPRestService) isNetworkJoined(networkID string) bool { namedLock.LockAcquire(stateJoinedNetworks) defer namedLock.LockRelease(stateJoinedNetworks) - if service.state.joinedNetworks == nil { - service.state.joinedNetworks = make(map[string]struct{}) - } - _, exists := service.state.joinedNetworks[networkID] return exists @@ -1819,16 +1815,13 @@ func (service *HTTPRestService) publishNetworkContainer(w http.ResponseWriter, r switch r.Method { case "POST": - // Join Network if not joined already - isNetworkJoined = service.isNetworkJoined(req.NetworkID) - if !isNetworkJoined { - publishResponse, publishError, err = service.joinNetwork(req.NetworkID, req.JoinNetworkURL) - if err == nil { - isNetworkJoined = true - } else { - returnMessage = err.Error() - returnCode = NetworkJoinFailed - } + // Join the network + publishResponse, publishError, err = service.joinNetwork(req.NetworkID, req.JoinNetworkURL) + if err == nil { + isNetworkJoined = true + } else { + returnMessage = err.Error() + returnCode = NetworkJoinFailed } if isNetworkJoined {