Skip to content

Commit 199980c

Browse files
committed
CNS_Fixing debug API
The GetIPAddressesMatchingStates now returns IPConfigurationStatus type, which also includes PodInfo along with IP address and state fix : minor formatting
1 parent cab6615 commit 199980c

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

cns/NetworkContainerContract.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ type GetIPAddressesRequest struct {
238238

239239
// GetIPAddressStateResponse is used in CNS IPAM mode as a response to get IP address state
240240
type GetIPAddressStateResponse struct {
241-
IPAddresses []IPAddressState
242-
Response Response
241+
IPConfigurationStatus[] IPConfigurationStatus
242+
Response Response
243243
}
244244

245245
// IPAddressState Only used in the GetIPConfig API to return IP's that match a filter

cns/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type HTTPService interface {
4747
MarkIPAsPendingRelease(numberToMark int) (map[string]IPConfigurationStatus, error)
4848
}
4949

50-
// This is used for KubernetesCRD orchastrator Type where NC has multiple ips.
50+
// This is used for KubernetesCRD orchestrator Type where NC has multiple ips.
5151
// This struct captures the state for SecondaryIPs associated to a given NC
5252
type IPConfigurationStatus struct {
5353
NCID string

cns/cnsclient/cli.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ func getCmd(client *CNSClient, arg string) error {
6767
case cns.PendingRelease:
6868
states = append(states, cns.PendingRelease)
6969

70+
case cns.PendingProgramming:
71+
states = append(states, cns.PendingProgramming)
72+
7073
default:
7174
states = append(states, cns.Allocated)
7275
states = append(states, cns.Available)
7376
states = append(states, cns.PendingRelease)
77+
states = append(states, cns.PendingProgramming)
7478
}
7579

7680
addr, err := client.GetIPAddressesMatchingStates(states...)
@@ -83,7 +87,7 @@ func getCmd(client *CNSClient, arg string) error {
8387
}
8488

8589
// Sort the addresses based on IP, then write to stdout
86-
func printIPAddresses(addrSlice []cns.IPAddressState) {
90+
func printIPAddresses(addrSlice []cns.IPConfigurationStatus) {
8791
sort.Slice(addrSlice, func(i, j int) bool {
8892
return addrSlice[i].IPAddress < addrSlice[j].IPAddress
8993
})

cns/cnsclient/cnsclient.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func (cnsClient *CNSClient) ReleaseIPAddress(orchestratorContext []byte) error {
319319

320320
// GetIPAddressesWithStates takes a variadic number of string parameters, to get all IP Addresses matching a number of states
321321
// usage GetIPAddressesWithStates(cns.Available, cns.Allocated)
322-
func (cnsClient *CNSClient) GetIPAddressesMatchingStates(StateFilter ...string) ([]cns.IPAddressState, error) {
322+
func (cnsClient *CNSClient) GetIPAddressesMatchingStates(StateFilter ...string) ([]cns.IPConfigurationStatus, error) {
323323
var (
324324
resp cns.GetIPAddressStateResponse
325325
err error
@@ -328,7 +328,7 @@ func (cnsClient *CNSClient) GetIPAddressesMatchingStates(StateFilter ...string)
328328
)
329329

330330
if len(StateFilter) == 0 {
331-
return []cns.IPAddressState{}, nil
331+
return resp.IPConfigurationStatus, nil
332332
}
333333

334334
url := cnsClient.connectionURL + cns.GetIPAddresses
@@ -341,33 +341,33 @@ func (cnsClient *CNSClient) GetIPAddressesMatchingStates(StateFilter ...string)
341341
err = json.NewEncoder(&body).Encode(payload)
342342
if err != nil {
343343
log.Errorf("encoding json failed with %v", err)
344-
return resp.IPAddresses, err
344+
return resp.IPConfigurationStatus, err
345345
}
346346

347347
res, err = http.Post(url, contentTypeJSON, &body)
348348
if err != nil {
349349
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
350-
return resp.IPAddresses, err
350+
return resp.IPConfigurationStatus, err
351351
}
352352

353353
defer res.Body.Close()
354354

355355
if res.StatusCode != http.StatusOK {
356356
errMsg := fmt.Sprintf("[Azure CNSClient] GetIPAddressesMatchingStates invalid http status code: %v", res.StatusCode)
357357
log.Errorf(errMsg)
358-
return resp.IPAddresses, fmt.Errorf(errMsg)
358+
return resp.IPConfigurationStatus, fmt.Errorf(errMsg)
359359
}
360360

361361
err = json.NewDecoder(res.Body).Decode(&resp)
362362
if err != nil {
363363
log.Errorf("[Azure CNSClient] Error received while parsing GetIPAddressesMatchingStates response resp:%v err:%v", res.Body, err.Error())
364-
return resp.IPAddresses, err
364+
return resp.IPConfigurationStatus, err
365365
}
366366

367367
if resp.Response.ReturnCode != 0 {
368368
log.Errorf("[Azure CNSClient] GetIPAddressesMatchingStates received error response :%v", resp.Response.Message)
369-
return resp.IPAddresses, fmt.Errorf(resp.Response.Message)
369+
return resp.IPConfigurationStatus, fmt.Errorf(resp.Response.Message)
370370
}
371371

372-
return resp.IPAddresses, err
372+
return resp.IPConfigurationStatus, err
373373
}

cns/cnsclient/cnsclient_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ func TestCNSClientRequestAndRelease(t *testing.T) {
233233
t.Fatalf("Expected to not fail when releasing IP reservation found with context: %+v", err)
234234
}
235235

236-
ipaddresses, err := cnsClient.GetIPAddressesMatchingStates(cns.Available)
236+
ipaddresses, err := cnsClient.GetIPAddressesMatchingStates("Available")
237+
fmt.Println(ipaddresses)
237238
if err != nil {
238239
t.Fatalf("Get allocated IP addresses failed %+v", err)
239240
}

cns/restserver/ipam.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,24 @@ func (service *HTTPRestService) getIPAddressesHandler(w http.ResponseWriter, r *
227227
}
228228

229229
// Get all IPConfigs matching a state, and append to a slice of IPAddressState
230-
resp.IPAddresses = filterIPConfigsMatchingState(service.PodIPConfigState, req.IPConfigStateFilter, filterFunc)
230+
resp.IPConfigurationStatus = filterIPConfigsMatchingState(service.PodIPConfigState, req.IPConfigStateFilter, filterFunc)
231231

232232
return
233233
}
234234

235235
// filter the ipconfigs in CNS matching a state (Available, Allocated, etc.) and return in a slice
236-
func filterIPConfigsMatchingState(toBeAdded map[string]cns.IPConfigurationStatus, states []string, f func(cns.IPConfigurationStatus, []string) bool) []cns.IPAddressState {
237-
vsf := make([]cns.IPAddressState, 0)
236+
func filterIPConfigsMatchingState(toBeAdded map[string]cns.IPConfigurationStatus, states []string, f func(cns.IPConfigurationStatus, []string) bool) []cns.IPConfigurationStatus {
237+
vsf := make([]cns.IPConfigurationStatus, 0)
238238
for _, v := range toBeAdded {
239239
if f(v, states) {
240-
ip := cns.IPAddressState{
241-
IPAddress: v.IPAddress,
242-
State: v.State,
240+
ipconfigstate := cns.IPConfigurationStatus {
241+
IPAddress: v.IPAddress,
242+
State: v.State,
243+
OrchestratorContext: v.OrchestratorContext,
244+
NCID: v.NCID,
245+
ID: v.ID,
243246
}
244-
vsf = append(vsf, ip)
247+
vsf = append(vsf, ipconfigstate)
245248
}
246249
}
247250
return vsf

0 commit comments

Comments
 (0)