Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cns/cnsclient/cnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (cnsClient *CNSClient) RequestIPAddress(orchestratorContext []byte) (*cns.G
httpc := &http.Client{}
url := cnsClient.connectionURL + cns.RequestIPConfig

payload := &cns.GetNetworkContainerRequest{
payload := &cns.GetIPConfigRequest{
OrchestratorContext: orchestratorContext,
}

Expand Down Expand Up @@ -268,7 +268,7 @@ func (cnsClient *CNSClient) ReleaseIPAddress(orchestratorContext []byte) error {
url := cnsClient.connectionURL + cns.ReleaseIPConfig
log.Printf("ReleaseIPAddress url %v", url)

payload := &cns.GetNetworkContainerRequest{
payload := &cns.GetIPConfigRequest{
OrchestratorContext: orchestratorContext,
}

Expand Down
6 changes: 5 additions & 1 deletion cns/cnsclient/cnsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ func TestMain(m *testing.M) {
defer os.RemoveAll(tmpLogDir)
defer os.Remove(tmpFileState.Name())

logName := "azure-cns.log"
fmt.Printf("Test logger file: %v", tmpLogDir+"/"+logName)
fmt.Printf("Test state :%v", tmpFileState.Name())

if err != nil {
panic(err)
}

logger.InitLogger("azure-cns.log", 0, 0, tmpLogDir)
logger.InitLogger(logName, 0, 0, tmpLogDir+"/")
config := common.ServiceConfig{}

httpRestService, err := restserver.NewHTTPRestService(&config)
Expand Down
9 changes: 5 additions & 4 deletions cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (service *HTTPRestService) requestIPConfigHandler(w http.ResponseWriter, r
}

// retrieve ipconfig from nc
returnCode, returnMessage = service.validateIpConfigRequest(ipconfigRequest)
_, returnCode, returnMessage = service.validateIpConfigRequest(ipconfigRequest)
if returnCode == Success {
if ipconfiguration, err = requestIPConfigHelper(service, ipconfigRequest); err != nil {
returnCode = FailedToAllocateIpConfig
Expand All @@ -54,7 +54,6 @@ func (service *HTTPRestService) requestIPConfigHandler(w http.ResponseWriter, r

func (service *HTTPRestService) releaseIPConfigHandler(w http.ResponseWriter, r *http.Request) {
var (
podInfo cns.KubernetesPodInfo
req cns.GetIPConfigRequest
statusCode int
returnMessage string
Expand All @@ -81,7 +80,7 @@ func (service *HTTPRestService) releaseIPConfigHandler(w http.ResponseWriter, r
logger.Response(service.Name, resp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)
}()

statusCode, returnMessage = service.validateIpConfigRequest(req)
podInfo, statusCode, returnMessage := service.validateIpConfigRequest(req)

if err = service.releaseIPConfig(podInfo); err != nil {
statusCode = NotFound
Expand Down Expand Up @@ -146,12 +145,14 @@ func (service *HTTPRestService) releaseIPConfig(podInfo cns.KubernetesPodInfo) e
if ipID != "" {
if ipconfig, isExist := service.PodIPConfigState[ipID]; isExist {
service.setIPConfigAsAvailable(ipconfig, podInfo)
logger.Printf("Released IP %+v for pod %+v", ipconfig.IPSubnet, podInfo)

} else {
logger.Errorf("Failed to get release ipconfig. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")
return fmt.Errorf("releaseIPConfig failed. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")
}
} else {
logger.Printf("SetIPConfigAsAvailable failed to release, no allocation found for pod")
logger.Errorf("SetIPConfigAsAvailable failed to release, no allocation found for pod")
return nil
}
return nil
Expand Down
13 changes: 7 additions & 6 deletions cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,22 +622,23 @@ func (service *HTTPRestService) SendNCSnapShotPeriodically(ncSnapshotIntervalInM
}
}

func (service *HTTPRestService) validateIpConfigRequest(ipConfigRequest cns.GetIPConfigRequest) (int, string) {
func (service *HTTPRestService) validateIpConfigRequest(ipConfigRequest cns.GetIPConfigRequest) (cns.KubernetesPodInfo, int, string) {
var podInfo cns.KubernetesPodInfo

if service.state.OrchestratorType != cns.KubernetesCRD {
return UnsupportedOrchestratorType, fmt.Sprintf("ReleaseIPConfig API supported only for kubernetes orchestrator")
return podInfo, UnsupportedOrchestratorType, fmt.Sprintf("ReleaseIPConfig API supported only for kubernetes orchestrator")
}

if ipConfigRequest.OrchestratorContext == nil {
return EmptyOrchestratorContext, fmt.Sprintf("OrchastratorContext is not set in the req: %+v", ipConfigRequest)
return podInfo, EmptyOrchestratorContext, fmt.Sprintf("OrchastratorContext is not set in the req: %+v", ipConfigRequest)
}

// retrieve podinfo from orchestrator context
var podInfo cns.KubernetesPodInfo
if err := json.Unmarshal(ipConfigRequest.OrchestratorContext, &podInfo); err != nil {
return UnsupportedOrchestratorContext, err.Error()
return podInfo, UnsupportedOrchestratorContext, err.Error()
}

return Success, ""
return podInfo, Success, ""
}

func (service *HTTPRestService) populateIpConfigInfoFromNCUntransacted(ncId string, ipConfiguration *cns.IPConfiguration) error {
Expand Down