Documentation
¶
Overview ¶
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. *
Index ¶
- Constants
- func AppendEndpointStatus(newStatus *ccev2.EndpointStatus, status models.EndpointState, code string) bool
- func AppendEndpointStatusWithMessage(newStatus *ccev2.EndpointStatus, status models.EndpointState, code string, ...) bool
- func ConverteIPAllocation2EndpointAddress(result *ipam.AllocationResult, family ccev2.IPFamily) *ccev2.AddressPair
- func DeleteEndpointAndWait(ctx context.Context, cceEndpointClient *watchers.CCEEndpointClient, ...) (err error)
- func GetEndpointCrossCache(ctx context.Context, cceEndpointClient *watchers.CCEEndpointClient, ...) (*ccev2.CCEEndpoint, error)
- func GetPodNameFromCEP(cep *ccev2.CCEEndpoint) (namesapce, name string)
- func IsPSTSEndpoint(resource *ccev2.CCEEndpoint) bool
- func IsSameContainerID(ep *ccev2.CCEEndpoint, containerID string) bool
- func NewEndpointTemplate(containerID, netnsPath string, pod *corev1.Pod) *ccev2.CCEEndpoint
- func NewIPAM(networkResourceSetName string, isRdmaEndpointAllocator bool, ...) ipam.CNIIPAMServer
- func StartPodTrackerCleaner()
- type CCEEndpointGetterUpdater
- type DirectAllocatorStarter
- type DirectEndpointOperation
- type DirectIPAction
- type DirectIPAllocator
- type DirectIPAllocatorProvider
- type EndpointAPIHandler
- func (handler *EndpointAPIHandler) GetEndpointExtpluginStatus(ctx context.Context, namespace, name, containerID string) (models.ExtFeatureData, error)
- func (handler *EndpointAPIHandler) PutEndpointProbe(ctx context.Context, namespace, name, containerID, driver string) (*models.EndpointProbeResponse, error)
- type EndpointAllocator
- func (e *EndpointAllocator) ADD(family, owner, containerID, netns string) (ipv4Result, ipv6Result *ipam.AllocationResult, err error)
- func (e *EndpointAllocator) DEL(owner, containerID string) (err error)
- func (e *EndpointAllocator) DebugStatus() string
- func (e *EndpointAllocator) Dump() (allocv4 map[string]string, allocv6 map[string]string, status string)
- func (e *EndpointAllocator) GetIPAMType() string
- func (e *EndpointAllocator) GetPrimaryMacAddress() string
- func (e *EndpointAllocator) Restore()
- func (e *EndpointAllocator) RestoreFinished()
- func (e *EndpointAllocator) UpdatePrimaryMacAddress(newMacAddress string)
- type EndpointEventHandler
- type EndpointManager
- func (manager *EndpointManager) Create(resource *ccev2.CCEEndpoint) error
- func (manager *EndpointManager) Delete(namespace, name string) error
- func (manager *EndpointManager) Resync(ctx context.Context) error
- func (manager *EndpointManager) Start(ctx context.Context) error
- func (manager *EndpointManager) Update(resource *ccev2.CCEEndpoint) error
- type EndpointMunalAllocatorProvider
- type IPReserveInfo
- type K8sEventRegister
- type PodAllocationTracker
- func (t *PodAllocationTracker) Cleanup()
- func (t *PodAllocationTracker) CleanupAll()
- func (t *PodAllocationTracker) GetTrackingStartTime(owner string) (time.Time, bool)
- func (t *PodAllocationTracker) StartTracking(owner string) time.Time
- func (t *PodAllocationTracker) StopTracking(owner string) (time.Time, bool)
- type PodReleaseTracker
Constants ¶
const ( // PodTrackerCleanupInterval 定期清理间隔 PodTrackerCleanupInterval = 5 * time.Minute // PodTrackerExpirationTime Pod跟踪记录过期时间 PodTrackerExpirationTime = 10 * time.Minute )
const (
// Annotation key for storing Reserve IDs (same as in operator/watchers/psts_ipreserve.go)
AnnotationIPReserveIDs = "cce.baidubce.com/ip-reserve-ids"
)
Variables ¶
This section is empty.
Functions ¶
func AppendEndpointStatus ¶
func AppendEndpointStatus(newStatus *ccev2.EndpointStatus, status models.EndpointState, code string) bool
AppendEndpointStatus appends node status to given pod endpoint status
func AppendEndpointStatusWithMessage ¶
func AppendEndpointStatusWithMessage(newStatus *ccev2.EndpointStatus, status models.EndpointState, code string, message string) bool
AppendEndpointStatusWithMessage appends node status with a detailed message to given pod endpoint status
func ConverteIPAllocation2EndpointAddress ¶
func ConverteIPAllocation2EndpointAddress(result *ipam.AllocationResult, family ccev2.IPFamily) *ccev2.AddressPair
func DeleteEndpointAndWait ¶
func DeleteEndpointAndWait(ctx context.Context, cceEndpointClient *watchers.CCEEndpointClient, oldEP *ccev2.CCEEndpoint) (err error)
DeleteEndpointAndWait delete endpoint and wait for it to be deleted
func GetEndpointCrossCache ¶
func GetEndpointCrossCache(ctx context.Context, cceEndpointClient *watchers.CCEEndpointClient, namespace string, name string) (*ccev2.CCEEndpoint, error)
GetEndpointFromCache GetEndpointCrossCache try get endpoint from cache if endpoint is missing the try get from apiserver
func GetPodNameFromCEP ¶
func GetPodNameFromCEP(cep *ccev2.CCEEndpoint) (namesapce, name string)
func IsPSTSEndpoint ¶
func IsPSTSEndpoint(resource *ccev2.CCEEndpoint) bool
func IsSameContainerID ¶
func IsSameContainerID(ep *ccev2.CCEEndpoint, containerID string) bool
IsSameContainerID checks if two container ids are the same or not
func NewEndpointTemplate ¶
func NewEndpointTemplate(containerID, netnsPath string, pod *corev1.Pod) *ccev2.CCEEndpoint
NewEndpointTemplate create a Elastic CCE Endpoint
func NewIPAM ¶
func NewIPAM(networkResourceSetName string, isRdmaEndpointAllocator bool, primaryMacAddress string, ipamType string, nodeAddressing types.NodeAddressing, c ipam.Configuration, owner ipam.Owner, watcher *watchers.K8sWatcher, mtuConfig ipam.MtuConfiguration) ipam.CNIIPAMServer
func StartPodTrackerCleaner ¶
func StartPodTrackerCleaner()
StartPodTrackerCleaner 启动定期清理Pod跟踪记录的后台任务
Types ¶
type CCEEndpointGetterUpdater ¶
type CCEEndpointGetterUpdater interface {
Create(node *ccev2.CCEEndpoint) (*ccev2.CCEEndpoint, error)
Update(ewResource *ccev2.CCEEndpoint) (*ccev2.CCEEndpoint, error)
UpdateStatus(newResource *ccev2.CCEEndpoint) (*ccev2.CCEEndpoint, error)
Delete(namespace, name string) error
Lister() ccelister.CCEEndpointLister
}
CCEEndpointGetterUpdater defines the interface used to interact with the k8s apiserver to retrieve and update the CCEEndpoint custom resource
type DirectAllocatorStarter ¶
type DirectAllocatorStarter interface {
StartEndpointManager(ctx context.Context, getterUpdater CCEEndpointGetterUpdater) (EndpointEventHandler, error)
}
DirectAllocatorStarter is the interface an IPAM implementation must provide in order
type DirectEndpointOperation ¶
type DirectEndpointOperation interface {
// FilterAvailableSubnet returns the best subnet for the endpoint
FilterAvailableSubnetIds([]string, int) []*bcesync.BorrowedSubnet
// AllocateIP allocates an IP for the endpoint
// The meaning of reusing the IP address is to migrate the IP
// address to be used by the pod from one node to another
// if action.addressing is not nil, it means that the IP address is reused
// if action.addressing is nil, it means that the IP address is newly allocated
// Note: This method will be called repeatedly, and the implementer must support reentrant calls
AllocateIP(ctx context.Context, action *DirectIPAction) error
// DeleteIP When the fixed IP pod is recycled and the IP is no longer reused,
// for example, the workload is permanently deleted. At this time, the fixed
// the implement should only delete the IP address while its owner is euqal to action.owner
// IP that should be retained should be recycled.
DeleteIP(ctx context.Context, allocation *DirectIPAction) error
}
type DirectIPAction ¶
type DirectIPAction struct {
// NodeName is identifier describing the ip on which node
NodeName string
Owner string
// ClientToken is used for idempotent IP allocation retries.
// +optional
ClientToken string
// IP4/6 addresses assigned to this Endpoint
// this field used to dynamic allocate ip
// +optional
SubnetID string
// IP4/6 addresses assigned to this Endpoint
Addressing ccev2.AddressPairList
// Interface is the identifier describing the ip on which interface
// this field used as param to release ip
// +optional
Interface string
// A list of node selector requirements by node's labels.
// +optional
NodeSelectorRequirement []corev1.NodeSelectorRequirement `json:"matchExpressions,omitempty" protobuf:"bytes,1,rep,name=matchExpressions"`
}
type DirectIPAllocator ¶
type DirectIPAllocator interface {
// ResyncPool is called to synchronize the latest list of interfaces and IPs
ResyncPool(ctx context.Context, scopedLog *logrus.Entry) (map[string]ipamTypes.AllocationMap, error)
// NodeEndpoint returns the NodeEndpointOperation
NodeEndpoint(cep *ccev2.CCEEndpoint) (DirectEndpointOperation, error)
}
DirectIPAllocator is the interface an IPAM implementation must provide in order to provide IP allocation for a node. The structure implementing this API *must* be aware of the node connected to this implementation. This is achieved by considering the node context provided in AllocationImplementation.CreateNetResource() function and returning a NodeOperations implementation which performs operations in the context of that node.
type DirectIPAllocatorProvider ¶
type DirectIPAllocatorProvider interface {
Init(ctx context.Context) error
StartEndpointManager(ctx context.Context, getterUpdater CCEEndpointGetterUpdater) (EndpointEventHandler, error)
}
DirectIPAllocatorProvider defines the functions of IPAM provider front-end these are implemented by e.g. pkg/ipam/allocator/{privatecloudbase}.
type EndpointAPIHandler ¶
type EndpointAPIHandler struct {
// contains filtered or unexported fields
}
EndpointAPIHandler is the handler for the endpoint API.
func NewEndpointAPIHandler ¶
func NewEndpointAPIHandler(watcher *watchers.K8sWatcher) *EndpointAPIHandler
func (*EndpointAPIHandler) GetEndpointExtpluginStatus ¶
func (handler *EndpointAPIHandler) GetEndpointExtpluginStatus(ctx context.Context, namespace, name, containerID string) (models.ExtFeatureData, error)
GetEndpointExtpluginStatus returns the status of the extplugin. this method will block until all external plugin status have been ready.
func (*EndpointAPIHandler) PutEndpointProbe ¶
func (handler *EndpointAPIHandler) PutEndpointProbe(ctx context.Context, namespace, name, containerID, driver string) (*models.EndpointProbeResponse, error)
type EndpointAllocator ¶
type EndpointAllocator struct {
// contains filtered or unexported fields
}
EndpointAllocator It proxies the basic operation methods of ipam. Each time an IP application succeeds, a CCEEndpoint object will be created. During gc, the existing CCEEndpoint objects will be gc based on CCEEndpoint
func (*EndpointAllocator) ADD ¶
func (e *EndpointAllocator) ADD(family, owner, containerID, netns string) (ipv4Result, ipv6Result *ipam.AllocationResult, err error)
ADD allocates an IP for the given owner and returns the allocated IP.
func (*EndpointAllocator) DEL ¶
func (e *EndpointAllocator) DEL(owner, containerID string) (err error)
func (*EndpointAllocator) DebugStatus ¶
func (e *EndpointAllocator) DebugStatus() string
func (*EndpointAllocator) GetIPAMType ¶
func (e *EndpointAllocator) GetIPAMType() string
GetIPAMType returns the current IPAM type Returns empty string for normal IPAM, UnderlayRDMA for HPC, OverlayRDMA for ERI
func (*EndpointAllocator) GetPrimaryMacAddress ¶
func (e *EndpointAllocator) GetPrimaryMacAddress() string
GetPrimaryMacAddress returns the primary MAC address for RDMA Endpoint Allocator
func (*EndpointAllocator) Restore ¶
func (e *EndpointAllocator) Restore()
Restore all the IP addresses applied for by the current machine to the node cache pool
func (*EndpointAllocator) RestoreFinished ¶
func (e *EndpointAllocator) RestoreFinished()
func (*EndpointAllocator) UpdatePrimaryMacAddress ¶
func (e *EndpointAllocator) UpdatePrimaryMacAddress(newMacAddress string)
UpdatePrimaryMacAddress updates the primary MAC address for RDMA Endpoint Allocator
type EndpointEventHandler ¶
type EndpointEventHandler interface {
Create(resource *ccev2.CCEEndpoint) error
Update(resource *ccev2.CCEEndpoint) error
Delete(namespace, endpointName string) error
Resync(context.Context) error
}
EndpointEventHandler should implement the behavior to handle CCEEndpoint
type EndpointManager ¶
type EndpointManager struct {
// contains filtered or unexported fields
}
func NewEndpointManager ¶
func NewEndpointManager(getterUpdater CCEEndpointGetterUpdater, reuseIPImplement DirectIPAllocator, vpcClient *vpc.Client) *EndpointManager
func (*EndpointManager) Create ¶
func (manager *EndpointManager) Create(resource *ccev2.CCEEndpoint) error
func (*EndpointManager) Delete ¶
func (manager *EndpointManager) Delete(namespace, name string) error
Delete removes the endpoint from the endpointMap
func (*EndpointManager) Start ¶
func (manager *EndpointManager) Start(ctx context.Context) error
Start kicks of the NodeManager by performing the initial state synchronization and starting the background sync go routine
func (*EndpointManager) Update ¶
func (manager *EndpointManager) Update(resource *ccev2.CCEEndpoint) error
type IPReserveInfo ¶
type IPReserveInfo struct {
SubnetID string `json:"subnetId"`
Reserves map[string]string `json:"reserves"` // CIDR -> ReserveID
}
IPReserveInfo stores the mapping between CIDR and ReserveID Must match the definition in operator/watchers/psts_ipreserve.go
type K8sEventRegister ¶
type K8sEventRegister interface {
// K8sEventReceived is called to do metrics accounting for received
// Kubernetes events, as well as calculating timeouts for k8s watcher
// cache sync.
K8sEventReceived(apiGroupResourceName string, scope string, action string, valid, equal bool)
// K8sEventProcessed is called to do metrics accounting for each processed
// Kubernetes event.
K8sEventProcessed(scope string, action string, status bool)
// RegisterNetResourceSetSubscriber allows registration of subscriber.NetResourceSet
// implementations. Events for all NetResourceSet events (not just the local one)
// will be sent to the subscriber.
RegisterNetResourceSetSubscriber(s subscriber.NetResourceSet)
}
K8sEventRegister is used to register and handle events as they are processed by K8s controllers.
type PodAllocationTracker ¶
type PodAllocationTracker struct {
// contains filtered or unexported fields
}
PodAllocationTracker 跟踪Pod IP分配的端到端时间
func (*PodAllocationTracker) Cleanup ¶
func (t *PodAllocationTracker) Cleanup()
Cleanup 清理过期的Pod跟踪记录
func (*PodAllocationTracker) CleanupAll ¶
func (t *PodAllocationTracker) CleanupAll()
CleanupAll 清理所有Pod跟踪记录(用于测试)
func (*PodAllocationTracker) GetTrackingStartTime ¶
func (t *PodAllocationTracker) GetTrackingStartTime(owner string) (time.Time, bool)
GetTrackingStartTime 获取Pod的跟踪开始时间,不停止跟踪
func (*PodAllocationTracker) StartTracking ¶
func (t *PodAllocationTracker) StartTracking(owner string) time.Time
StartTracking 开始跟踪Pod的IP分配,如果已经在跟踪则返回首次开始时间
func (*PodAllocationTracker) StopTracking ¶
func (t *PodAllocationTracker) StopTracking(owner string) (time.Time, bool)
StopTracking 停止跟踪Pod并返回开始时间
type PodReleaseTracker ¶
type PodReleaseTracker struct {
// contains filtered or unexported fields
}
PodReleaseTracker 跟踪Pod IP回收的端到端时间
func (*PodReleaseTracker) CleanupAll ¶
func (t *PodReleaseTracker) CleanupAll()
CleanupAll 清理所有Pod回收跟踪记录(用于测试)
func (*PodReleaseTracker) GetTrackingStartTime ¶
func (t *PodReleaseTracker) GetTrackingStartTime(owner string) (time.Time, bool)
GetTrackingStartTime 获取Pod的跟踪开始时间,不停止跟踪
func (*PodReleaseTracker) StartTracking ¶
func (t *PodReleaseTracker) StartTracking(owner string) time.Time
StartTracking 开始跟踪Pod的IP回收,如果已经在跟踪则返回首次开始时间
func (*PodReleaseTracker) StopTracking ¶
func (t *PodReleaseTracker) StopTracking(owner string) (time.Time, bool)
StopTracking 停止跟踪Pod并返回开始时间