Skip to content

Commit 4096ab1

Browse files
authored
Merge pull request #808 from kmurudi/cns_fixdebugapi
CNS_Fixing debug API
2 parents ea07e4f + 5a6c484 commit 4096ab1

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

cns/NetworkContainerContract.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ type GetIPAddressStateResponse struct {
242242
Response Response
243243
}
244244

245+
// GetIPAddressStatusResponse is used in CNS IPAM mode as a response to get IP address, state and Pod info
246+
type GetIPAddressStatusResponse struct {
247+
IPConfigurationStatus[] IPConfigurationStatus
248+
Response Response
249+
}
250+
245251
// IPAddressState Only used in the GetIPConfig API to return IP's that match a filter
246252
type IPAddressState struct {
247253
IPAddress string

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: 6 additions & 2 deletions
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,12 +87,12 @@ 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
})
9094

9195
for _, addr := range addrSlice {
92-
fmt.Printf("%+v\n", addr)
96+
cns.IPConfigurationStatus.String(addr)
9397
}
9498
}

cns/cnsclient/cnsclient.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,16 @@ 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 (
324-
resp cns.GetIPAddressStateResponse
324+
resp cns.GetIPAddressStatusResponse
325325
err error
326326
res *http.Response
327327
body bytes.Buffer
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,5 @@ func TestCNSClientRequestAndRelease(t *testing.T) {
245245
if ipaddresses[0].IPAddress != desiredIpAddress && ipaddresses[0].State != cns.Available {
246246
t.Fatalf("Available IP address does not match expected, address state: %+v", ipaddresses)
247247
}
248+
fmt.Println(ipaddresses)
248249
}

cns/restserver/ipam.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (service *HTTPRestService) GetPendingProgramIPConfigs() []cns.IPConfigurati
193193
func (service *HTTPRestService) getIPAddressesHandler(w http.ResponseWriter, r *http.Request) {
194194
var (
195195
req cns.GetIPAddressesRequest
196-
resp cns.GetIPAddressStateResponse
196+
resp cns.GetIPAddressStatusResponse
197197
statusCode int
198198
returnMessage string
199199
err error
@@ -227,21 +227,17 @@ 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,
243-
}
244-
vsf = append(vsf, ip)
240+
vsf = append(vsf, v)
245241
}
246242
}
247243
return vsf

0 commit comments

Comments
 (0)