cellohelper

package
v1.6.2-rc Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VkeTagPrefix        = "volc:vke:"
	VkePlatformTagKey   = VkeTagPrefix + "createdby-vke-flag"
	VkePlatformTagValue = "true"
	VkeComponentTagKey  = VkeTagPrefix + "created-by"
	VkeInstanceIdTagKey = VkeTagPrefix + "ecs-id"

	K8sTagPrefix        = "k8s:cello:"
	K8sComponentTagKey  = K8sTagPrefix + "created-by"
	K8sInstanceIdTagKey = K8sTagPrefix + "ecs-id"

	Component = "cello"
)
View Source
const (
	ENITypePrimary   = "primary"
	ENITypeSecondary = "secondary"
	ENITypeTrunk     = "trunk"

	ENIStatusAvailable = "Available"
	ENIStatusInuse     = "InUse"
)

Variables

This section is empty.

Functions

func BuildFilterForDescribeNetworkInterfacesInput

func BuildFilterForDescribeNetworkInterfacesInput(tags map[string]string) []*vpc.TagFilterForDescribeNetworkInterfacesInput

func BuildTagsForCreateNetworkInterfaceInput

func BuildTagsForCreateNetworkInterfaceInput(tags map[string]string) []*vpc.TagForCreateNetworkInterfaceInput

Types

type InstanceLimitManager

type InstanceLimitManager interface {
	// GetLimit get InstanceLimits of ecs instance
	GetLimit() InstanceLimits
	// Update update InstanceLimits of ecs instance
	Update()
	// UpdateTrunk update trunk eni to InstanceLimits
	UpdateTrunk(trunk *types.ENI)
}

func NewInstanceLimitManager

func NewInstanceLimitManager(api VolcAPI) (InstanceLimitManager, error)

type InstanceLimits

type InstanceLimits struct {
	InstanceLimitsAttr
	ENICustomer int
	// currently support only one
	TrunkENI *types.ENI
}

InstanceLimits quota and limit.

func (*InstanceLimits) BranchENI

func (l *InstanceLimits) BranchENI() int

func (*InstanceLimits) ENIAvailable

func (l *InstanceLimits) ENIAvailable() int

ENIAvailable get quota minus the custom eni and primary eni.

func (*InstanceLimits) NonPrimaryENI

func (l *InstanceLimits) NonPrimaryENI() int

NonPrimaryENI return the number of eni except primary eni.

func (*InstanceLimits) String

func (l *InstanceLimits) String() string

func (*InstanceLimits) SupportTrunk

func (l *InstanceLimits) SupportTrunk() bool

SupportTrunk support trunk or not.

type InstanceLimitsAttr

type InstanceLimitsAttr struct {
	ENITotal       int
	ENIQuota       int
	IPv4MaxPerENI  int
	IPv6MaxPerENI  int
	TrunkSupported bool
}

InstanceLimitsAttr contains the basic quota and limit information of ecs instance used by cello.

type InstanceMetadata

type InstanceMetadata struct {
	VpcId            string
	InstanceId       string
	InstanceType     string
	PrimaryENIId     string
	PrimaryENIMac    string
	AvailabilityZone string
	Region           string
}

func (*InstanceMetadata) GetAvailabilityZone

func (m *InstanceMetadata) GetAvailabilityZone() string

func (*InstanceMetadata) GetInstanceId

func (m *InstanceMetadata) GetInstanceId() string

func (*InstanceMetadata) GetInstanceType

func (m *InstanceMetadata) GetInstanceType() string

func (*InstanceMetadata) GetPrimaryENIId

func (m *InstanceMetadata) GetPrimaryENIId() string

func (*InstanceMetadata) GetPrimaryENIMac

func (m *InstanceMetadata) GetPrimaryENIMac() string

func (*InstanceMetadata) GetRegion

func (m *InstanceMetadata) GetRegion() string

func (*InstanceMetadata) GetVpcId

func (m *InstanceMetadata) GetVpcId() string

type InstanceMetadataGetter

type InstanceMetadataGetter interface {
	GetVpcId() string
	GetInstanceId() string
	GetInstanceType() string
	GetPrimaryENIId() string
	GetPrimaryENIMac() string
	GetAvailabilityZone() string
	GetRegion() string
}

func GetInstanceMetadata

func GetInstanceMetadata() InstanceMetadataGetter

GetInstanceMetadata return basic information of ecs instance, only obtain once.

type PodSubnet

type PodSubnet struct {
	ZoneId         string `json:"zoneId"`
	VpcId          string `json:"vpcId"`
	SubnetId       string `json:"subnetId"`
	IPv4Cidr       string `json:"ipv4Cidr,omitempty"`
	IPv6Cidr       string `json:"ipv6Cidr,omitempty"`
	TotalIpv4Count int    `json:"totalIpv4Count"`

	// status
	sync.RWMutex
	Disable                 bool      `json:"disable,omitempty"`
	AvailableIpAddressCount int       `json:"availableIpAddressCount"`
	LastUpdate              time.Time `json:"lastUpdate"`
}

func (*PodSubnet) Available

func (s *PodSubnet) Available(ipFamily types.IPFamily) bool

func (*PodSubnet) DisableSubnet

func (s *PodSubnet) DisableSubnet()

func (*PodSubnet) Enable

func (s *PodSubnet) Enable() bool

func (*PodSubnet) EnableSubnet

func (s *PodSubnet) EnableSubnet()

func (*PodSubnet) GetAvailableIpAddressCount

func (s *PodSubnet) GetAvailableIpAddressCount() int

func (*PodSubnet) IPFamily

func (s *PodSubnet) IPFamily() types.IPFamily

IPFamily return types.IPFamily of PodSubnet.

func (*PodSubnet) UpdateAvailableIpAddressCount

func (s *PodSubnet) UpdateAvailableIpAddressCount(q int)

type PodSubnetManagerConfig

type PodSubnetManagerConfig struct {
	EventLimiter                *rate.Limiter
	SubnetInsufficientThreshold float64
	// contains filtered or unexported fields
}

func DefaultPodSubnetManagerConfig

func DefaultPodSubnetManagerConfig() *PodSubnetManagerConfig

type PodSubnetManagerOption

type PodSubnetManagerOption func(config *PodSubnetManagerConfig)

func WithDefaultEventLimiter

func WithDefaultEventLimiter() PodSubnetManagerOption

func WithEventLimiter

func WithEventLimiter(limiter *rate.Limiter) PodSubnetManagerOption

func WithEventRecord

func WithEventRecord(eventRecord *tracing.Tracer) PodSubnetManagerOption

func WithSubnetInsufficientThreshold

func WithSubnetInsufficientThreshold(threshold float64) PodSubnetManagerOption

type SecurityGroupManager

type SecurityGroupManager interface {
	// GetSecurityGroups get security groups used by pods
	GetSecurityGroups() []string
	// UpdateSecurityGroups update security groups used by pods
	UpdateSecurityGroups(sec []string) error
}

func NewSecurityGroupManager

func NewSecurityGroupManager() SecurityGroupManager

type SortablePodSubnets

type SortablePodSubnets []*PodSubnet

func (SortablePodSubnets) Len

func (s SortablePodSubnets) Len() int

func (SortablePodSubnets) Less

func (s SortablePodSubnets) Less(i, j int) bool

func (SortablePodSubnets) Swap

func (s SortablePodSubnets) Swap(i, j int)

type Status

type Status struct {
	ZoneId           string                `json:"zone_id"`
	VpcId            string                `json:"vpc_id"`
	PodSubnets       map[string]*PodSubnet `json:"pod_subnets,omitempty"`
	LegacyPodSubnets map[string]*PodSubnet `json:"legacy_pod_subnets,omitempty"`
}

Status of SubnetManager.

type SubnetManager

type SubnetManager interface {
	// FlushSubnets flush PodSubnet in SubnetManager
	FlushSubnets(subnetIds ...string) error

	// GetPodSubnet get PodSubnet, get by openapi if not exist in SubnetManager
	GetPodSubnet(subnetId string) *PodSubnet

	// GetUpdatedPodSubnet update PodSubnet and then get it
	GetUpdatedPodSubnet(subnetId string) (subnet *PodSubnet, err error)

	// SelectSubnet select a PodSubnet from available PodSubnets in SubnetManager
	SelectSubnet(ipFamily types.IPFamily, options ...UpdateSubnetsStatusOption) *PodSubnet

	// UpdateSubnetsStatus update status of all PodSubnet in SubnetManager
	// If the option of aging is carried, subnets within the time limit will not be updated
	UpdateSubnetsStatus(options ...UpdateSubnetsStatusOption) error

	// DisableSubnet disable a PodSubnet, it will not be used
	DisableSubnet(subnetId string)

	// Status return status of SubnetManager
	Status() *Status
}

func NewPodSubnetManager

func NewPodSubnetManager(zoneId, vpcId string, client ec2.APIGroupSubnet, options ...PodSubnetManagerOption) (SubnetManager, error)

type UpdateSubnetsStatusConfig

type UpdateSubnetsStatusConfig struct {
	Aging time.Duration
}

UpdateSubnetsStatusConfig config used while update status of PodSubnets.

type UpdateSubnetsStatusOption

type UpdateSubnetsStatusOption func(config *UpdateSubnetsStatusConfig)

UpdateSubnetsStatusOption option used while update status of PodSubnets.

func WithAging

func WithAging(aging time.Duration) UpdateSubnetsStatusOption

WithAging aging option.

func WithUnlimitedAging

func WithUnlimitedAging() UpdateSubnetsStatusOption

WithUnlimitedAging option for no timeliness requirement.

type VolcAPI

type VolcAPI interface {

	// AllocENI creates an ENI and attaches it to the instance
	AllocENI(subnet string, securityGroups []string, trunk bool, ipCnt int) (*types.ENI, error)

	// FreeENI detaches ENI interface and deletes it
	FreeENI(eniID string) error

	// GetENI get eni by mac from metadata
	GetENI(mac string) (*types.ENI, error)

	// GetAttachedENIs return counts of attached enis except rdma eni and list of eni created by cello
	GetAttachedENIs(withTrunk bool) (int, []*types.ENI, error)

	GetSecondaryENIMACs() ([]string, error)

	// GetENIIPList returns the IPs for a given ENI from instance metadata service
	GetENIIPList(eniMac string) ([]net.IP, []net.IP, error)

	// AllocIPAddresses allocates numIPs IP addresses on an ENI
	AllocIPAddresses(eniID, eniMac string, v4Cnt, v6Cnt int) ([]net.IP, []net.IP, error)

	// DeallocIPAddresses deallocates the IP addresses from an ENI
	DeallocIPAddresses(eniID, eniMac string, ipv4s, ipv6s []net.IP) error

	// GetInstanceLimit return instance InstanceLimits
	GetInstanceLimit() (*InstanceLimits, error)
}

type VolcApiImpl

type VolcApiImpl struct {

	// metadata info
	InstanceMetadataGetter
	// contains filtered or unexported fields
}

func New

func New(apiClient ec2.EC2, ipStack types.IPFamily, subnetMgr SubnetManager, instanceMetadata InstanceMetadataGetter,
	platform string) (*VolcApiImpl, error)

func (*VolcApiImpl) AllocENI

func (e *VolcApiImpl) AllocENI(subnetId string, securityGroups []string, trunk bool, ipCnt int) (*types.ENI, error)

func (*VolcApiImpl) AllocIPAddresses

func (e *VolcApiImpl) AllocIPAddresses(eniID, eniMac string, v4Cnt, v6Cnt int) ([]net.IP, []net.IP, error)

func (*VolcApiImpl) DeallocIPAddresses

func (e *VolcApiImpl) DeallocIPAddresses(eniID, eniMac string, ipv4s, ipv6s []net.IP) error

func (*VolcApiImpl) FreeENI

func (e *VolcApiImpl) FreeENI(eniID string) error

func (*VolcApiImpl) GetAttachedENIs

func (e *VolcApiImpl) GetAttachedENIs(withTrunk bool) (int, []*types.ENI, error)

func (*VolcApiImpl) GetENI

func (e *VolcApiImpl) GetENI(mac string) (*types.ENI, error)

GetENI get types.ENI by mac from metadata.

func (*VolcApiImpl) GetENIIPList

func (e *VolcApiImpl) GetENIIPList(eniMac string) ([]net.IP, []net.IP, error)

GetENIIPList returns the IPs for a given ENI from instance metadata service.

func (*VolcApiImpl) GetInstanceLimit

func (e *VolcApiImpl) GetInstanceLimit() (*InstanceLimits, error)

GetInstanceLimit return IP address limit per ENI.

func (*VolcApiImpl) GetSecondaryENIMACs

func (e *VolcApiImpl) GetSecondaryENIMACs() ([]string, error)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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