floatingip

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 22 Imported by: 0

Documentation

Overview

* Tencent is pleased to support the open source community by making TKEStack available. * * Copyright (C) 2012-2019 Tencent. 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 * * https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License.

* Tencent is pleased to support the open source community by making TKEStack available. * * Copyright (C) 2012-2019 Tencent. 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 * * https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License.

* Tencent is pleased to support the open source community by making TKEStack available. * * Copyright (C) 2012-2019 Tencent. 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 * * https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License.

* Tencent is pleased to support the open source community by making TKEStack available. * * Copyright (C) 2012-2019 Tencent. 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 * * https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License.

* Tencent is pleased to support the open source community by making TKEStack available. * * Copyright (C) 2012-2019 Tencent. 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 * * https://opensource.org/licenses/Apache-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 OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoEnoughIP is error when there is no available floatingIPs
	ErrNoEnoughIP = fmt.Errorf("no enough available ips left")
)

Functions

func CreateTestIPAM

func CreateTestIPAM(t *testing.T, objs ...runtime.Object) (*crdIpam, crdInformer.SharedInformerFactory)

CreateTestIPAM creates an ipam for testing

func Minus

func Minus(a, b net.IP) int64

Minus compute how many ips between two given ip.

Types

type Attr

type Attr struct {
	// NodeName is needed to send unassign request to cloud provider on resync
	NodeName string
	// uid is used to differentiate a deleting pod and a newly created pod with the same name such as statefulsets
	// or tapp pod
	Uid string
	// Release policy
	Policy constant.ReleasePolicy `json:"-"`
}

Attr stores attrs about this pod

func (Attr) String

func (a Attr) String() string

type FloatingIP

type FloatingIP struct {
	Key       string
	IP        net.IP
	UpdatedAt time.Time
	Labels    map[string]string
	Policy    uint16
	NodeName  string
	PodUid    string
	// contains filtered or unexported fields
}

FloatingIP defines a floating ip

func New

func New(pool *FloatingIPPool, ip net.IP, key string, attr *Attr, updateAt time.Time) *FloatingIP

New creates a new FloatingIP

func (*FloatingIP) Assign

func (f *FloatingIP) Assign(key string, attr *Attr, updateAt time.Time) *FloatingIP

Assign updates key, attr, updatedAt of FloatingIP

func (*FloatingIP) CloneWith

func (f *FloatingIP) CloneWith(key string, attr *Attr, updateAt time.Time) *FloatingIP

CloneWith creates a new FloatingIP and updates key, attr, updatedAt

func (FloatingIP) String

func (f FloatingIP) String() string

type FloatingIPInfo

type FloatingIPInfo struct {
	IPInfo constant.IPInfo
	FloatingIP
	NodeSubnets sets.String
}

FloatingIPInfo is floatingIP information

type FloatingIPPool

type FloatingIPPool struct {
	NodeSubnets []*net.IPNet // the node subnets
	nets.SparseSubnet
	sync.RWMutex
	// contains filtered or unexported fields
}

FloatingIPPool is FloatingIPPool structure.

func (*FloatingIPPool) Contains

func (fip *FloatingIPPool) Contains(ip net.IP) bool

Contains judge whether FloatingIP struct contains a given ip.

func (*FloatingIPPool) InsertIP

func (fip *FloatingIPPool) InsertIP(ip net.IP) bool

#lizard forgives InsertIP can insert a given ip to FloatingIP struct.

func (*FloatingIPPool) MarshalJSON

func (fip *FloatingIPPool) MarshalJSON() ([]byte, error)

MarshalJSON can marshal FloatingIPPoolConf to byte slice.

func (*FloatingIPPool) RemoveIP

func (fip *FloatingIPPool) RemoveIP(ip net.IP) bool

RemoveIP can remove a given ip from FloatingIP struct.

func (*FloatingIPPool) String

func (fip *FloatingIPPool) String() string

String can transform FloatingIP to string.

func (*FloatingIPPool) UnmarshalJSON

func (fip *FloatingIPPool) UnmarshalJSON(data []byte) error

UnmarshalJSON can unmarshal byte slice to FloatingIPPoolConf

type FloatingIPPoolConf

type FloatingIPPoolConf struct {
	NodeSubnets []*nets.IPNet `json:"nodeSubnets"` // the node subnets
	// Deprecated, use NodeSubnets instead
	RoutableSubnet *nets.IPNet `json:"routableSubnet,omitempty"` // the node subnet
	IPs            []string    `json:"ips"`
	Subnet         *nets.IPNet `json:"subnet"` // the vip subnet
	Gateway        net.IP      `json:"gateway"`
	Vlan           uint16      `json:"vlan,omitempty"`
}

FloatingIPPoolConf is FloatingIP config structure.

type FloatingIPSlice

type FloatingIPSlice []*FloatingIPPool

func (FloatingIPSlice) Len

func (s FloatingIPSlice) Len() int

Len returns number of FloatingIPSlice.

func (FloatingIPSlice) Less

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

Less compares two given ip.

func (FloatingIPSlice) Swap

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

Swap can swap two ip in FloatingIPSlice.

type IPAM

type IPAM interface {
	// ConfigurePool init floatingIP pool.
	ConfigurePool([]*FloatingIPPool) error
	// ReleaseIPs releases given ips as long as their keys match and returned released and unreleased map
	// released and unreleased map are guaranteed to be none nil even if err is not nil
	// unreleased map stores ip with its latest key if key changed
	ReleaseIPs(map[string]string) (map[string]string, map[string]string, error)
	// AllocateSpecificIP allocate pod a specific IP.
	AllocateSpecificIP(string, net.IP, Attr) error
	// AllocateInSubnet allocate subnet of IPs.
	AllocateInSubnet(string, *net.IPNet, Attr) (net.IP, error)
	// AllocateInSubnetsAndIPRange allocates an ip for each ip range array of the input node subnet.
	// It guarantees allocating all ips or no ips.
	AllocateInSubnetsAndIPRange(string, *net.IPNet, [][]nets.IPRange, Attr) ([]net.IP, error)
	// AllocateInSubnetWithKey allocate a floatingIP in given subnet and key.
	AllocateInSubnetWithKey(oldK, newK, subnet string, attr Attr) error
	// ReserveIP can reserve a IP entitled by a terminated pod. Attributes **expect policy attr** will be updated.
	// Returns true if key or attr updated.
	ReserveIP(oldK, newK string, attr Attr) (bool, error)
	// UpdateAttr update floatingIP's release policy and attrs according to ip and key
	UpdateAttr(string, net.IP, Attr) error
	// Release release a given IP.
	Release(string, net.IP) error
	// First returns the first matched IP by key.
	First(string) (*FloatingIPInfo, error) // returns nil,nil if key is not found
	// ByIP transform a given IP to FloatingIP struct.
	ByIP(net.IP) (FloatingIP, error)
	// ByPrefix filter floatingIPs by prefix key.
	ByPrefix(string) ([]*FloatingIPInfo, error)
	// ByKeyword returns floatingIP set by a given keyword.
	ByKeyword(string) ([]FloatingIP, error)
	// ByKeyAndIPRanges finds an allocated ip for each []nets.IPRange by key.
	// If input [][]nets.IPRange is nil or empty, it finds all allocated ips by key.
	// Otherwise, it always return the same size of []*FloatingIPInfo as [][]nets.IPRange, the element of
	// []*FloatingIPInfo may be nil when it can't find an allocated ip for the same index of []iprange.
	ByKeyAndIPRanges(string, [][]nets.IPRange) ([]*FloatingIPInfo, error)
	// NodeSubnets returns node's subnet.
	NodeSubnet(net.IP) *net.IPNet
	// NodeSubnetsByIPRanges finds an unallocated ip for each []nets.IPRange, and returns their intersection
	// node subnets.
	NodeSubnetsByIPRanges(ipranges [][]nets.IPRange) (sets.String, error)
	// implements metrics Collector interface
	prometheus.Collector
}

IPAM interface which implemented by kubernetes CRD

func NewCrdIPAM

func NewCrdIPAM(fipClient crd_clientset.Interface, informer crdInformer.FloatingIPInformer) IPAM

NewCrdIPAM init IPAM struct.

Jump to

Keyboard shortcuts

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