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
6 changes: 3 additions & 3 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const (
DetachContainerFromNetwork = "/network/detachcontainerfromnetwork"
RequestIPConfig = "/network/requestipconfig"
ReleaseIPConfig = "/network/releaseipconfig"
GetIPAddresses = "/debug/getipaddresses"
GetPodIPOrchestratorContext = "/debug/getpodcontext"
GetHTTPRestData = "/debug/getrestdata"
DebugIPAddresses = "/debug/ipaddresses"
DebugPodContext = "/debug/podcontext"
DebugRestData = "/debug/restdata"
)

// NetworkContainer Prefixes
Expand Down
6 changes: 3 additions & 3 deletions cns/cnsclient/cnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (cnsClient *CNSClient) GetIPAddressesMatchingStates(stateFilter ...cns.IPCo
return resp.IPConfigurationStatus, nil
}

url := cnsClient.connectionURL + cns.GetIPAddresses
url := cnsClient.connectionURL + cns.DebugIPAddresses
log.Printf("GetIPAddressesMatchingStates url %v", url)

payload := &cns.GetIPAddressesRequest{
Expand Down Expand Up @@ -375,7 +375,7 @@ func (cnsClient *CNSClient) GetPodOrchestratorContext() (map[string]string, erro
res *http.Response
)

url := cnsClient.connectionURL + cns.GetPodIPOrchestratorContext
url := cnsClient.connectionURL + cns.DebugPodContext
log.Printf("GetPodIPOrchestratorContext url %v", url)

res, err = http.Get(url)
Expand Down Expand Up @@ -414,7 +414,7 @@ func (cnsClient *CNSClient) GetHTTPServiceData() (restserver.GetHTTPServiceDataR
res *http.Response
)

url := cnsClient.connectionURL + cns.GetHTTPRestData
url := cnsClient.connectionURL + cns.DebugRestData
log.Printf("GetHTTPServiceStruct url %v", url)

res, err = http.Get(url)
Expand Down
106 changes: 29 additions & 77 deletions cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,97 +182,49 @@ func (service *HTTPRestService) GetPodIPConfigState() map[string]cns.IPConfigura
return podIPConfigState
}

func (service *HTTPRestService) getPodIPIDByOrchestratorContexthandler(w http.ResponseWriter, r *http.Request) {
var (
resp cns.GetPodContextResponse
statusCode types.ResponseCode
returnMessage string
err error
)

statusCode = types.UnexpectedError

defer func() {
if err != nil {
resp.Response.ReturnCode = statusCode
resp.Response.Message = returnMessage
}

err = service.Listener.Encode(w, &resp)
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
}()

resp.PodContext = service.GetPodIPIDByOrchestratorContext()
}

func (service *HTTPRestService) GetPodIPIDByOrchestratorContext() map[string]string {
func (service *HTTPRestService) handleDebugPodContext(w http.ResponseWriter, r *http.Request) {
service.RLock()
defer service.RUnlock()
return service.PodIPIDByPodInterfaceKey
}

func (service *HTTPRestService) GetHTTPRestDataHandler(w http.ResponseWriter, r *http.Request) {
var (
resp GetHTTPServiceDataResponse
returnMessage string
err error
)

defer func() {
if err != nil {
resp.Response.ReturnCode = types.UnexpectedError
resp.Response.Message = returnMessage
}

err = service.Listener.Encode(w, &resp)
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
}()

resp.HTTPRestServiceData = service.GetHTTPStruct()
resp := cns.GetPodContextResponse{
PodContext: service.PodIPIDByPodInterfaceKey,
}
err := service.Listener.Encode(w, &resp)
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
}

func (service *HTTPRestService) GetHTTPStruct() HTTPRestServiceData {
func (service *HTTPRestService) handleDebugRestData(w http.ResponseWriter, r *http.Request) {
service.RLock()
defer service.RUnlock()

return HTTPRestServiceData{
PodIPIDByPodInterfaceKey: service.PodIPIDByPodInterfaceKey,
PodIPConfigState: service.PodIPConfigState,
IPAMPoolMonitor: service.IPAMPoolMonitor.GetStateSnapshot(),
resp := GetHTTPServiceDataResponse{
HTTPRestServiceData: HTTPRestServiceData{
PodIPIDByPodInterfaceKey: service.PodIPIDByPodInterfaceKey,
PodIPConfigState: service.PodIPConfigState,
IPAMPoolMonitor: service.IPAMPoolMonitor.GetStateSnapshot(),
},
}
err := service.Listener.Encode(w, &resp)
logger.Response(service.Name, resp, resp.Response.ReturnCode, err)
}

func (service *HTTPRestService) getIPAddressesHandler(w http.ResponseWriter, r *http.Request) {
var (
req cns.GetIPAddressesRequest
resp cns.GetIPAddressStatusResponse
statusCode types.ResponseCode
returnMessage string
err error
)

statusCode = types.UnexpectedError

defer func() {
if err != nil {
resp.Response.ReturnCode = statusCode
resp.Response.Message = returnMessage
func (service *HTTPRestService) handleDebugIPAddresses(w http.ResponseWriter, r *http.Request) {
var req cns.GetIPAddressesRequest
if err := service.Listener.Decode(w, r, &req); err != nil {
resp := cns.GetIPAddressStatusResponse{
Response: cns.Response{
ReturnCode: types.UnexpectedError,
Message: err.Error(),
},
}

err = service.Listener.Encode(w, &resp)
logger.ResponseEx(service.Name, req, resp, resp.Response.ReturnCode, err)
}()

err = service.Listener.Decode(w, r, &req)
if err != nil {
returnMessage = err.Error()
logger.Errorf("getIPAddressesHandler decode failed because %v, GetIPAddressesRequest is %v",
returnMessage, req)
return
}

// Get all IPConfigs matching a state, and append to a slice of IPAddressState
resp.IPConfigurationStatus = filter.MatchAnyIPConfigState(service.PodIPConfigState, filter.PredicatesForStates(req.IPConfigStateFilter...)...)
// Get all IPConfigs matching a state and return in the response
resp := cns.GetIPAddressStatusResponse{
IPConfigurationStatus: filter.MatchAnyIPConfigState(service.PodIPConfigState, filter.PredicatesForStates(req.IPConfigStateFilter...)...),
}
err := service.Listener.Encode(w, &resp)
logger.ResponseEx(service.Name, req, resp, resp.Response.ReturnCode, err)
}

// GetAllocatedIPConfigs returns a filtered list of IPs which are in
Expand Down
6 changes: 3 additions & 3 deletions cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func (service *HTTPRestService) Init(config *common.ServiceConfig) error {
listener.AddHandler(cns.RequestIPConfig, newHandlerFuncWithHistogram(service.requestIPConfigHandler, httpRequestLatency))
listener.AddHandler(cns.ReleaseIPConfig, newHandlerFuncWithHistogram(service.releaseIPConfigHandler, httpRequestLatency))
listener.AddHandler(cns.NmAgentSupportedApisPath, service.nmAgentSupportedApisHandler)
listener.AddHandler(cns.GetIPAddresses, service.getIPAddressesHandler)
listener.AddHandler(cns.GetPodIPOrchestratorContext, service.getPodIPIDByOrchestratorContexthandler)
listener.AddHandler(cns.GetHTTPRestData, service.GetHTTPRestDataHandler)
listener.AddHandler(cns.DebugIPAddresses, service.handleDebugIPAddresses)
listener.AddHandler(cns.DebugPodContext, service.handleDebugPodContext)
listener.AddHandler(cns.DebugRestData, service.handleDebugRestData)

// handlers for v0.2
listener.AddHandler(cns.V2Prefix+cns.SetEnvironmentPath, service.setEnvironment)
Expand Down