restserver

package
v1.15.22 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 51 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GetHomeAzAPIName = "GetHomeAz"
	ContextTimeOut   = 2 * 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")
)

Functions

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 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
	IPAMPoolMonitor          cns.IPAMPoolMonitor

	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) CreateOrUpdateNetworkContainerInternal

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

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

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) 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) 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) 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) 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 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 K8sSWIFTv2Middleware added in v1.5.22

type K8sSWIFTv2Middleware struct {
	Cli client.Client
}

func (*K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper added in v1.5.22

func (m *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, failureHandler cns.IPConfigsHandlerFunc) cns.IPConfigsHandlerFunc

IPConfigsRequestHandlerWrapper is the middleware function for handling SWIFT v2 IP configs requests for AKS-SWIFT. This function wrapped the default SWIFT request and release IP configs handlers.

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
}

type SFSWIFTv2Middleware added in v1.5.22

type SFSWIFTv2Middleware struct {
	CnsClient *client.Client
}

func (*SFSWIFTv2Middleware) IPConfigsRequestHandlerWrapper added in v1.5.22

func (m *SFSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(_, _ cns.IPConfigsHandlerFunc) cns.IPConfigsHandlerFunc

IPConfigsRequestHandlerWrapper is the middleware function for handling SWIFT v2 IP config requests for SF standalone scenario. This function wraps the default SWIFT request and release IP configs handlers.

Jump to

Keyboard shortcuts

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