Skip to content

Commit 727a6e6

Browse files
committed
CNS_Fixing debug API
The GetIPAddressesMatchingStates now returns IPConfigurationStatus type, which also includes PodInfo along with IP address and state
1 parent 08f0006 commit 727a6e6

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
@@ -233,8 +233,8 @@ type GetIPAddressesRequest struct {
233233

234234
// GetIPAddressStateResponse is used in CNS IPAM mode as a response to get IP address state
235235
type GetIPAddressStateResponse struct {
236-
IPAddresses []IPAddressState
237-
Response Response
236+
IPConfigurationStatus[] IPConfigurationStatus
237+
Response Response
238238
}
239239

240240
// 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
@@ -46,7 +46,7 @@ type HTTPService interface {
4646
MarkIPAsPendingRelease(numberToMark int) (map[string]IPConfigurationStatus, error)
4747
}
4848

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

cns/cnsclient/cli.go

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

71+
case cns.PendingProgramming:
72+
states = append(states, cns.PendingProgramming)
73+
7174
default:
7275
states = append(states, cns.Allocated)
7376
states = append(states, cns.Available)
7477
states = append(states, cns.PendingRelease)
78+
states = append(states, cns.PendingProgramming)
7579
}
7680

7781
addr, err := client.GetIPAddressesMatchingStates(states...)
@@ -84,7 +88,7 @@ func getCmd(client *CNSClient, arg string) error {
8488
}
8589

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

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
@@ -227,7 +227,8 @@ func TestCNSClientRequestAndRelease(t *testing.T) {
227227
t.Fatalf("Expected to not fail when releasing IP reservation found with context: %+v", err)
228228
}
229229

230-
ipaddresses, err := cnsClient.GetIPAddressesMatchingStates(cns.Available)
230+
ipaddresses, err := cnsClient.GetIPAddressesMatchingStates("Available")
231+
fmt.Println(ipaddresses)
231232
if err != nil {
232233
t.Fatalf("Get allocated IP addresses failed %+v", err)
233234
}

cns/restserver/ipam.go

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

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

212212
return
213213
}
214214

215215
// filter the ipconfigs in CNS matching a state (Available, Allocated, etc.) and return in a slice
216-
func filterIPConfigsMatchingState(toBeAdded map[string]cns.IPConfigurationStatus, states []string, f func(cns.IPConfigurationStatus, []string) bool) []cns.IPAddressState {
217-
vsf := make([]cns.IPAddressState, 0)
216+
func filterIPConfigsMatchingState(toBeAdded map[string]cns.IPConfigurationStatus, states []string, f func(cns.IPConfigurationStatus, []string) bool) []cns.IPConfigurationStatus {
217+
vsf := make([]cns.IPConfigurationStatus, 0)
218218
for _, v := range toBeAdded {
219219
if f(v, states) {
220-
ip := cns.IPAddressState{
221-
IPAddress: v.IPAddress,
222-
State: v.State,
220+
ipconfigstate := cns.IPConfigurationStatus{
221+
IPAddress: v.IPAddress,
222+
State: v.State,
223+
OrchestratorContext: v.OrchestratorContext,
224+
NCID: v.NCID,
225+
ID: v.ID,
223226
}
224-
vsf = append(vsf, ip)
227+
vsf = append(vsf, ipconfigstate)
225228
}
226229
}
227230
return vsf

0 commit comments

Comments
 (0)