Skip to content

Commit df9c086

Browse files
authored
fix: pass podinfo to CNS delete (#649)
* fix: present podinfo to delete * fix: return empty struct instead of pointer
1 parent e1282ab commit df9c086

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

cns/cnsclient/cnsclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (cnsClient *CNSClient) RequestIPAddress(orchestratorContext []byte) (*cns.G
218218
httpc := &http.Client{}
219219
url := cnsClient.connectionURL + cns.RequestIPConfig
220220

221-
payload := &cns.GetNetworkContainerRequest{
221+
payload := &cns.GetIPConfigRequest{
222222
OrchestratorContext: orchestratorContext,
223223
}
224224

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

271-
payload := &cns.GetNetworkContainerRequest{
271+
payload := &cns.GetIPConfigRequest{
272272
OrchestratorContext: orchestratorContext,
273273
}
274274

cns/cnsclient/cnsclient_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ func TestMain(m *testing.M) {
105105
defer os.RemoveAll(tmpLogDir)
106106
defer os.Remove(tmpFileState.Name())
107107

108+
logName := "azure-cns.log"
109+
fmt.Printf("Test logger file: %v", tmpLogDir+"/"+logName)
110+
fmt.Printf("Test state :%v", tmpFileState.Name())
111+
108112
if err != nil {
109113
panic(err)
110114
}
111115

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

115119
httpRestService, err := restserver.NewHTTPRestService(&config)

cns/restserver/ipam.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (service *HTTPRestService) requestIPConfigHandler(w http.ResponseWriter, r
3030
}
3131

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

5555
func (service *HTTPRestService) releaseIPConfigHandler(w http.ResponseWriter, r *http.Request) {
5656
var (
57-
podInfo cns.KubernetesPodInfo
5857
req cns.GetIPConfigRequest
5958
statusCode int
6059
returnMessage string
@@ -81,7 +80,7 @@ func (service *HTTPRestService) releaseIPConfigHandler(w http.ResponseWriter, r
8180
logger.Response(service.Name, resp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)
8281
}()
8382

84-
statusCode, returnMessage = service.validateIpConfigRequest(req)
83+
podInfo, statusCode, returnMessage := service.validateIpConfigRequest(req)
8584

8685
if err = service.releaseIPConfig(podInfo); err != nil {
8786
statusCode = NotFound
@@ -146,12 +145,14 @@ func (service *HTTPRestService) releaseIPConfig(podInfo cns.KubernetesPodInfo) e
146145
if ipID != "" {
147146
if ipconfig, isExist := service.PodIPConfigState[ipID]; isExist {
148147
service.setIPConfigAsAvailable(ipconfig, podInfo)
148+
logger.Printf("Released IP %+v for pod %+v", ipconfig.IPSubnet, podInfo)
149+
149150
} else {
150151
logger.Errorf("Failed to get release ipconfig. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")
151152
return fmt.Errorf("releaseIPConfig failed. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")
152153
}
153154
} else {
154-
logger.Printf("SetIPConfigAsAvailable failed to release, no allocation found for pod")
155+
logger.Errorf("SetIPConfigAsAvailable failed to release, no allocation found for pod")
155156
return nil
156157
}
157158
return nil

cns/restserver/util.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,22 +622,23 @@ func (service *HTTPRestService) SendNCSnapShotPeriodically(ncSnapshotIntervalInM
622622
}
623623
}
624624

625-
func (service *HTTPRestService) validateIpConfigRequest(ipConfigRequest cns.GetIPConfigRequest) (int, string) {
625+
func (service *HTTPRestService) validateIpConfigRequest(ipConfigRequest cns.GetIPConfigRequest) (cns.KubernetesPodInfo, int, string) {
626+
var podInfo cns.KubernetesPodInfo
627+
626628
if service.state.OrchestratorType != cns.KubernetesCRD {
627-
return UnsupportedOrchestratorType, fmt.Sprintf("ReleaseIPConfig API supported only for kubernetes orchestrator")
629+
return podInfo, UnsupportedOrchestratorType, fmt.Sprintf("ReleaseIPConfig API supported only for kubernetes orchestrator")
628630
}
629631

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

634636
// retrieve podinfo from orchestrator context
635-
var podInfo cns.KubernetesPodInfo
636637
if err := json.Unmarshal(ipConfigRequest.OrchestratorContext, &podInfo); err != nil {
637-
return UnsupportedOrchestratorContext, err.Error()
638+
return podInfo, UnsupportedOrchestratorContext, err.Error()
638639
}
639640

640-
return Success, ""
641+
return podInfo, Success, ""
641642
}
642643

643644
func (service *HTTPRestService) populateIpConfigInfoUntransacted(ipConfigStatus ipConfigurationStatus, ipConfiguration *cns.IPConfiguration) error {

0 commit comments

Comments
 (0)