Join vnet as a part of NC publish (#451)

Join vnet before publishing NC. This is required as nmagent may be
restarted which causes the NC publishing to fail.
This commit is contained in:
Ashvin Deodhar 2019-12-04 10:35:49 -08:00 коммит произвёл GitHub
Родитель 6ca873ce05
Коммит 02cec02390
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 11 добавлений и 18 удалений

Просмотреть файл

@ -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 {