restserver

package
v1.5.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 43 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GetHomeAzAPIName = "GetHomeAz"
	ContextTimeOut   = 5 * time.Second
)
View Source
const (
	ContainerIDLength = 8
	InterfaceName     = "eth0"
)
View Source
const (
	EndpointStoreKey = "Endpoints"
)
View Source
const SWIFT = "SWIFT-POSTROUTING"

Variables

View Source
var (
	ErrStoreEmpty             = errors.New("empty endpoint state store")
	ErrParsePodIPFailed       = errors.New("failed to parse pod's ip")
	ErrNoNCs                  = errors.New("no NCs found in the CNS internal state")
	ErrOptManageEndpointState = errors.New("CNS is not set to manage the endpoint state")
	ErrEndpointStateNotFound  = errors.New("endpoint state could not be found in the statefile")
)
View Source
var (
	ErrInvalidNcURLFormat = errors.New("Invalid network container url format")
)
View Source
var (
	HTTPRequestLatency = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "http_request_latency_seconds",
			Help: "Request latency in seconds by endpoint, verb, and response code.",

			Buckets: prometheus.ExponentialBuckets(0.001, 2, 15),
		},
		[]string{"url", "verb", "cns_return_code"},
	)
)

Functions

func NewHandlerFuncWithHistogram added in v1.5.26

func NewHandlerFuncWithHistogram(handler http.HandlerFunc, histogram *prometheus.HistogramVec) http.HandlerFunc

func ResponseCodeToError

func ResponseCodeToError(responseCode types.ResponseCode) error

ResponseCodeToError converts a cns response code to error type. If the response code is OK, then return value is nil

Types

type CNIConflistGenerator

type CNIConflistGenerator interface {
	Generate() error
	Close() error
}

type CNSRESTError

type CNSRESTError struct {
	ResponseCode types.ResponseCode
}

CNSRESTError represents a CNS error

func (*CNSRESTError) Error

func (c *CNSRESTError) Error() string

type EndpointInfo

type EndpointInfo struct {
	PodName       string
	PodNamespace  string
	IfnameToIPMap map[string]*IPInfo // key : interface name, value : IPInfo
	HnsEndpointID string
	HostVethName  string
}

type GetEndpointResponse added in v1.5.17

type GetEndpointResponse struct {
	Response     Response     `json:"response"`
	EndpointInfo EndpointInfo `json:"endpointInfo"`
}

GetEndpointResponse describes response from the The GetEndpoint API.

type GetHTTPServiceDataResponse

type GetHTTPServiceDataResponse struct {
	HTTPRestServiceData HTTPRestServiceData `json:"HTTPRestServiceData"`
	Response            Response            `json:"Response"`
}

type HTTPRestService

type HTTPRestService struct {
	*cns.Service

	PodIPIDByPodInterfaceKey map[string][]string                  // PodInterfaceId is key and value is slice of Pod IP (SecondaryIP) uuids.
	PodIPConfigState         map[string]cns.IPConfigurationStatus // Secondary IP ID(uuid) is key

	sync.RWMutex

	EndpointState      map[string]*EndpointInfo // key : container id
	EndpointStateStore store.KeyValueStore

	IPConfigsHandlerMiddleware cns.IPConfigsHandlerMiddleware
	// contains filtered or unexported fields
}

HTTPRestService represents http listener for CNS - Container Networking Service.

func NewHTTPRestService

func NewHTTPRestService(config *common.ServiceConfig, wscli interfaceGetter, wsproxy wireserverProxy, nmagentClient nmagentClient,
	endpointStateStore store.KeyValueStore, gen CNIConflistGenerator, homeAzMonitor *HomeAzMonitor,
) (*HTTPRestService, error)

NewHTTPRestService creates a new HTTP Service object.

func (*HTTPRestService) AssignAvailableIPConfigs

func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([]cns.PodIpInfo, error)

Assigns an available IP from each NC on the NNC. If there is one NC then we expect to only have one IP return In the case of dualstack we would expect to have one IPv6 from one NC and one IPv4 from a second NC

func (*HTTPRestService) AssignDesiredIPConfigs

func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desiredIPAddresses []string) ([]cns.PodIpInfo, error)

Assigns a pod with all IPs desired

func (*HTTPRestService) AttachIPConfigsHandlerMiddleware added in v1.5.19

func (service *HTTPRestService) AttachIPConfigsHandlerMiddleware(middleware cns.IPConfigsHandlerMiddleware)

func (*HTTPRestService) CreateHostNCApipaEndpoint added in v1.5.26

func (service *HTTPRestService) CreateHostNCApipaEndpoint(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) CreateOrUpdateNetworkContainerInternal

func (service *HTTPRestService) CreateOrUpdateNetworkContainerInternal(req *cns.CreateNetworkContainerRequest) types.ResponseCode

This API will be called by CNS RequestController on CRD update.

func (*HTTPRestService) DeleteHostNCApipaEndpoint added in v1.5.26

func (service *HTTPRestService) DeleteHostNCApipaEndpoint(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) DeleteNetworkContainerInternal

func (service *HTTPRestService) DeleteNetworkContainerInternal(
	req cns.DeleteNetworkContainerRequest,
) types.ResponseCode

DeleteNetworkContainerInternal deletes a network container.

func (*HTTPRestService) EndpointHandlerAPI added in v1.5.17

func (service *HTTPRestService) EndpointHandlerAPI(w http.ResponseWriter, r *http.Request)

EndpointHandlerAPI forwards the endpoint related APIs to GetEndpointHandler or UpdateEndpointHandler based on the http method

func (*HTTPRestService) GetAllNetworkContainers added in v1.5.26

func (service *HTTPRestService) GetAllNetworkContainers(w http.ResponseWriter, r *http.Request)

the function is to get all network containers based on given OrchestratorContext

func (*HTTPRestService) GetAssignedIPConfigs

func (service *HTTPRestService) GetAssignedIPConfigs() []cns.IPConfigurationStatus

GetAssignedIPConfigs returns a filtered list of IPs which are in Assigned State.

func (*HTTPRestService) GetAvailableIPConfigs

func (service *HTTPRestService) GetAvailableIPConfigs() []cns.IPConfigurationStatus

GetAvailableIPConfigs returns a filtered list of IPs which are in Available State.

func (*HTTPRestService) GetEndpointHandler added in v1.5.17

func (service *HTTPRestService) GetEndpointHandler(w http.ResponseWriter, r *http.Request)

GetEndpointHandler handles the incoming GetEndpoint requests with http Get method

func (*HTTPRestService) GetEndpointHelper added in v1.5.17

func (service *HTTPRestService) GetEndpointHelper(endpointID string) (*EndpointInfo, error)

GetEndpointHelper returns the state of the given endpointId

func (*HTTPRestService) GetExistingIPConfig

func (service *HTTPRestService) GetExistingIPConfig(podInfo cns.PodInfo) ([]cns.PodIpInfo, bool, error)

Returns the current IP configs for a pod if they exist

func (*HTTPRestService) GetNetworkContainerByOrchestratorContext added in v1.5.26

func (service *HTTPRestService) GetNetworkContainerByOrchestratorContext(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) GetNetworkContainerInternal

func (service *HTTPRestService) GetNetworkContainerInternal(
	req cns.GetNetworkContainerRequest,
) (cns.GetNetworkContainerResponse, types.ResponseCode)

GetNetworkContainerInternal gets network container details.

func (*HTTPRestService) GetPartitionKey

func (service *HTTPRestService) GetPartitionKey() (dncPartitionKey string)

GetPartitionKey - Get dnc/service partition key

func (*HTTPRestService) GetPendingProgramIPConfigs

func (service *HTTPRestService) GetPendingProgramIPConfigs() []cns.IPConfigurationStatus

GetPendingProgramIPConfigs returns a filtered list of IPs which are in PendingProgramming State.

func (*HTTPRestService) GetPendingReleaseIPConfigs

func (service *HTTPRestService) GetPendingReleaseIPConfigs() []cns.IPConfigurationStatus

GetPendingReleaseIPConfigs returns a filtered list of IPs which are in PendingRelease State.

func (*HTTPRestService) GetPodIPConfigState

func (service *HTTPRestService) GetPodIPConfigState() map[string]cns.IPConfigurationStatus

func (*HTTPRestService) HandleDebugIPAddresses added in v1.5.26

func (service *HTTPRestService) HandleDebugIPAddresses(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) HandleDebugPodContext added in v1.5.26

func (service *HTTPRestService) HandleDebugPodContext(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) HandleDebugRestData added in v1.5.26

func (service *HTTPRestService) HandleDebugRestData(w http.ResponseWriter, r *http.Request)

func (*HTTPRestService) Init

func (service *HTTPRestService) Init(config *common.ServiceConfig) error

Init starts the CNS listener.

func (*HTTPRestService) MarkExistingIPsAsPendingRelease

func (service *HTTPRestService) MarkExistingIPsAsPendingRelease(pendingIPIDs []string) error

MarkExistingIPsAsPendingRelease is called when CNS is starting up and there are existing ipconfigs in the CRD that are marked as pending.

func (*HTTPRestService) MarkIPAsPendingRelease

func (service *HTTPRestService) MarkIPAsPendingRelease(totalIpsToRelease int) (map[string]cns.IPConfigurationStatus, error)

MarkIPAsPendingRelease will set the IPs which are in PendingProgramming or Available to PendingRelease state It will try to update [totalIpsToRelease] number of ips.

func (*HTTPRestService) MarkIpsAsAvailableUntransacted

func (service *HTTPRestService) MarkIpsAsAvailableUntransacted(ncID string, newHostNCVersion int)

MarkIpsAsAvailableUntransacted will update pending programming IPs to available if NMAgent side's programmed nc version keep up with nc version. Note: this func is an untransacted API as the caller will take a Service lock

func (*HTTPRestService) MarkNIPsPendingRelease added in v1.5.21

func (service *HTTPRestService) MarkNIPsPendingRelease(n int) (map[string]cns.IPConfigurationStatus, error)

MarkIPAsPendingRelease will attempt to set [n] number of ips to PendingRelease state. It will start with any IPs in PendingProgramming state and then move on to any IPs in Allocated state until it has reached the target release quantity. If it is unable to set the expected number of IPs to PendingRelease, it will revert the changed IPs and return an error. MarkNIPsPendingRelease is no-op if [n] is not a positive integer.

func (*HTTPRestService) MustEnsureNoStaleNCs

func (service *HTTPRestService) MustEnsureNoStaleNCs(validNCIDs []string)

func (*HTTPRestService) MustGenerateCNIConflistOnce

func (service *HTTPRestService) MustGenerateCNIConflistOnce()

MustGenerateCNIConflistOnce will generate the CNI conflist once if the service was initialized with a conflist generator. If not, this is a no-op.

func (*HTTPRestService) ReconcileIPAMState

func (service *HTTPRestService) ReconcileIPAMState(ncReqs []*cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo, nnc *v1alpha.NodeNetworkConfig) types.ResponseCode

func (*HTTPRestService) RegisterPProfEndpoints

func (service *HTTPRestService) RegisterPProfEndpoints()

func (*HTTPRestService) ReleaseIPConfigHandler added in v1.5.26

func (service *HTTPRestService) ReleaseIPConfigHandler(w http.ResponseWriter, r *http.Request)

ReleaseIPConfigHandler frees the IP assigned to a pod from CNS

func (*HTTPRestService) ReleaseIPConfigHandlerHelper added in v1.5.26

func (service *HTTPRestService) ReleaseIPConfigHandlerHelper(ctx context.Context, ipconfigsRequest cns.IPConfigsRequest) (*cns.IPConfigsResponse, error)

ReleaseIPConfigHandlerHelper validates the request and removes the endpoint associated with the pod

func (*HTTPRestService) ReleaseIPConfigsHandler added in v1.5.26

func (service *HTTPRestService) ReleaseIPConfigsHandler(w http.ResponseWriter, r *http.Request)

ReleaseIPConfigsHandler frees multiple IPConfigs from the CNS state

func (*HTTPRestService) RequestIPConfigHandler added in v1.5.26

func (service *HTTPRestService) RequestIPConfigHandler(w http.ResponseWriter, r *http.Request)

RequestIPConfigHandler requests an IPConfig from the CNS state

func (*HTTPRestService) RequestIPConfigsHandler added in v1.5.26

func (service *HTTPRestService) RequestIPConfigsHandler(w http.ResponseWriter, r *http.Request)

RequestIPConfigsHandler requests multiple IPConfigs from the CNS state

func (*HTTPRestService) SendNCSnapShotPeriodically

func (service *HTTPRestService) SendNCSnapShotPeriodically(ctx context.Context, ncSnapshotIntervalInMinutes int)

Sets up periodic timer for sending network container snapshots

func (*HTTPRestService) SetNodeOrchestrator

func (service *HTTPRestService) SetNodeOrchestrator(r *cns.SetOrchestratorTypeRequest)

SetNodeOrchestrator :- Set node orchestrator after registering with mDNC

func (*HTTPRestService) Start

func (service *HTTPRestService) Start(config *common.ServiceConfig) error

Start starts the CNS listener.

func (*HTTPRestService) Stop

func (service *HTTPRestService) Stop()

Stop stops the CNS.

func (*HTTPRestService) SyncHostNCVersion

func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMode string)

SyncHostNCVersion will check NC version from NMAgent and save it as host NC version in container status. If NMAgent NC version got updated, CNS will refresh the pending programming IP status.

func (*HTTPRestService) SyncNodeStatus

func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string, contextFromCNI json.RawMessage) (returnCode types.ResponseCode, errStr string)

func (*HTTPRestService) UpdateEndpointHandler added in v1.5.17

func (service *HTTPRestService) UpdateEndpointHandler(w http.ResponseWriter, r *http.Request)

UpdateEndpointHandler handles the incoming UpdateEndpoint requests with http Patch method

func (*HTTPRestService) UpdateEndpointHelper added in v1.5.17

func (service *HTTPRestService) UpdateEndpointHelper(endpointID string, req cns.EndpointRequest) error

UpdateEndpointHelper updates the state of the given endpointId with HNSId or VethName

type HTTPRestServiceData

type HTTPRestServiceData struct {
	PodIPIDByPodInterfaceKey map[string][]string                  // PodInterfaceId is key and value is slice of Pod IP uuids.
	PodIPConfigState         map[string]cns.IPConfigurationStatus // secondaryipid(uuid) is key
}

HTTPRestServiceData represents in-memory CNS data in the debug API paths. TODO: add json tags for this struct as per linter suggestion, ignored for now as part of revert-PR

type HomeAzMonitor

type HomeAzMonitor struct {
	// contains filtered or unexported fields
}

func NewHomeAzMonitor

func NewHomeAzMonitor(client nmagentClient, cacheRefreshIntervalSecs time.Duration) *HomeAzMonitor

NewHomeAzMonitor creates a new HomeAzMonitor object

func (*HomeAzMonitor) GetHomeAz

GetHomeAz returns home az cache value directly

func (*HomeAzMonitor) Populate

func (h *HomeAzMonitor) Populate(ctx context.Context)

Populate makes call to nmagent to retrieve home az if getHomeAz api is supported by nmagent

func (*HomeAzMonitor) Start

func (h *HomeAzMonitor) Start()

Start starts a new thread to refresh home az cache

func (*HomeAzMonitor) Stop

func (h *HomeAzMonitor) Stop()

Stop ends the refresh thread

type IPInfo

type IPInfo struct {
	IPv4 []net.IPNet
	IPv6 []net.IPNet
}

type NoOpConflistGenerator

type NoOpConflistGenerator struct{}

func (*NoOpConflistGenerator) Close

func (*NoOpConflistGenerator) Close() error

func (*NoOpConflistGenerator) Generate

func (*NoOpConflistGenerator) Generate() error

type Response

type Response struct {
	ReturnCode types.ResponseCode
	Message    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL