cloudprovider

package
v0.0.0-...-5497e08 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlatformTypeAWS = "AWS"
)
View Source
const (
	PlatformTypeAzure = "Azure"
)
View Source
const (
	PlatformTypeGCP = "GCP"
)
View Source
const (
	// PlatformTypeOpenStack is the string representation for the OpenStack platform type.
	PlatformTypeOpenStack = "OpenStack"
)
View Source
const UserAgent = "cloud-network-config-controller"

Variables

View Source
var (
	NoNetworkInterfaceError  = errors.New("no retrievable network interface")
	AlreadyExistingIPError   = errors.New("the requested IP for assignment is already assigned")
	NonExistingIPError       = errors.New("the requested IP for removal is not assigned")
	UnexpectedURIErrorString = "the URI is not expected"
)

Functions

func UnexpectedURIError

func UnexpectedURIError(uri string) error

Types

type AWS

type AWS struct {
	CloudProvider
	// contains filtered or unexported fields
}

AWS implements the API wrapper for talking to the AWS cloud API

func (*AWS) AssignPrivateIP

func (a *AWS) AssignPrivateIP(ip net.IP, node *corev1.Node) error

AssignPrivateIP assigns the IP address to the node by re-providing all existing ones + the new one. It does this on a per-IP-family basis (since the AWS API is separated per family). If the IP is already existing: it returns an AlreadyExistingIPError.

func (*AWS) GetNodeEgressIPConfiguration

func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)

func (*AWS) ReleasePrivateIP

func (a *AWS) ReleasePrivateIP(ip net.IP, node *corev1.Node) error

ReleasePrivateIP un-assigns the IP address from the node. It does this on a per-IP-family basis (since the AWS API is separated per family). If the IP is non-existant: it returns an NonExistingIPError.

type Azure

type Azure struct {
	CloudProvider
	// contains filtered or unexported fields
}

Azure implements the API wrapper for talking to the Azure cloud API

func (*Azure) AssignPrivateIP

func (a *Azure) AssignPrivateIP(ip net.IP, node *corev1.Node) error

func (*Azure) GetNodeEgressIPConfiguration

func (a *Azure) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)

func (*Azure) ReleasePrivateIP

func (a *Azure) ReleasePrivateIP(ip net.IP, node *corev1.Node) error

type CloudProvider

type CloudProvider struct {
	CloudProviderIntf
	// contains filtered or unexported fields
}

type CloudProviderConfig

type CloudProviderConfig struct {
	PlatformType  string // one of AWS, Azure, GCP
	APIOverride   string // override the API endpoint URL. Used by all platforms.
	CredentialDir string // override the default credential directory
	ConfigDir     string // override the default config directory

	Region        string // region, only used by AWS
	AWSCAOverride string

	AzureEnvironment string // The azure "environment", which is a set of API endpoints
}

CloudProviderConfig is all the command-line options needed to initialize a cloud provider client.

type CloudProviderIntf

type CloudProviderIntf interface {

	// AssignPrivateIP attempts to assigning the IP address provided to the VM
	// instance corresponding to the corev1.Node provided on the cloud the
	// cluster is deployed on. NOTE: this operation is only performed against
	// the first network interface defined for the VM. It will return an
	// AlreadyExistingIPError if the IP provided is already associated with the
	// node, it's up to the caller to decide what to do with that.
	AssignPrivateIP(ip net.IP, node *corev1.Node) error

	// ReleasePrivateIP attempts to releasing the IP address provided from the
	// VM instance corresponding to the corev1.Node provided on the cloud the
	// cluster is deployed on. NOTE: this operation is only performed against
	// the first network interface defined for the VM.
	ReleasePrivateIP(ip net.IP, node *corev1.Node) error

	// GetNodeEgressIPConfiguration retrieves the egress IP configuration for
	// the node, following the convention the cloud uses. This means
	// specifically that: the IP capacity can be either hard-coded and global
	// for all instance types and IP families (GCP, Azure) or variable per
	// instance and IP family (AWS), also: the interface is either keyed by name
	// (GCP) or ID (Azure, AWS).
	GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)
	// contains filtered or unexported methods
}

func NewCloudProviderClient

func NewCloudProviderClient(cfg CloudProviderConfig, platformStatus *configv1.PlatformStatus, featureGates featuregates.FeatureGate) (CloudProviderIntf, error)

type CloudProviderWithMoveIntf

type CloudProviderWithMoveIntf interface {
	// MovePrivateIP is called instead of ReleasePrivateIP followed by
	// AssignPrivateIP if plugin implements CloudProviderWithMoveIntf. It
	// should effectively move IP address from nodeToDel to nodeToAdd, but not
	// necessarily remove resources from the cloud. E.g. in case of OpenStack
	// we don't want to delete the reservation Neutron port, but rather just
	// manipulate allowedAddressPairs on the nodeToDel and nodeToAdd ports to
	// move the IP from one node to another.
	MovePrivateIP(ip net.IP, nodeToAdd *corev1.Node, nodeToDel *corev1.Node) error
}

CloudProviderWithMoveIntf is additional interface that can be added to cloud plugins that can benefit from a separate set of operations on IP address failover, instead of running ReleasePrivateIP followed by AssignPrivateIP.

type FakeCloudProvider

type FakeCloudProvider struct {
	StateTracker []string
	// contains filtered or unexported fields
}

func NewFakeCloudProvider

func NewFakeCloudProvider(mockErrorOnAssign, mockErrorOnAssignWithExistingIPCondition, mockErrorOnRelease, mockErrorOnWait bool, delayedCompletion time.Duration) *FakeCloudProvider

func (*FakeCloudProvider) AssignPrivateIP

func (f *FakeCloudProvider) AssignPrivateIP(ip net.IP, node *corev1.Node) error

func (*FakeCloudProvider) GetNodeEgressIPConfiguration

func (f *FakeCloudProvider) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)

func (*FakeCloudProvider) ReleasePrivateIP

func (f *FakeCloudProvider) ReleasePrivateIP(ip net.IP, node *corev1.Node) error

type GCP

type GCP struct {
	CloudProvider
	// contains filtered or unexported fields
}

GCP implements the API wrapper for talking to the GCP cloud API

func (*GCP) AssignPrivateIP

func (g *GCP) AssignPrivateIP(ip net.IP, node *corev1.Node) error

AssignPrivateIP adds the IP to the associated instance's IP aliases. Important: GCP IP aliases can come in all forms, i.e: if you add 10.0.32.25 GCP can return 10.0.32.25/32 or 10.0.32.25 - we thus need to check for both when validating that the IP provided doesn't already exist

func (*GCP) GetNodeEgressIPConfiguration

func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)

func (*GCP) ReleasePrivateIP

func (g *GCP) ReleasePrivateIP(ip net.IP, node *corev1.Node) error

ReleasePrivateIP removes the IP alias from the associated instance. Important: GCP IP aliases can come in all forms, i.e: if you add 10.0.32.25 GCP can return 10.0.32.25/32 or 10.0.32.25

type NodeEgressIPConfiguration

type NodeEgressIPConfiguration struct {
	Interface string   `json:"interface"`
	IFAddr    ifAddr   `json:"ifaddr"`
	Capacity  capacity `json:"capacity"`
}
  • Interface - ID / Name, depending on the cloud's convention
  • IP address capacity for each node, where the capacity is either IP family agnostic or not.
  • Subnet information for the first network interface, IP family specific

func (*NodeEgressIPConfiguration) String

func (n *NodeEgressIPConfiguration) String() string

String implements the stringer interface for pointers to NodeEgressIPConfiguration. This is used for the unit tests as it simplifies printing of the actual values instead of returning the memory address that is being pointed to.

type OpenStack

type OpenStack struct {
	CloudProvider
	CloudProviderWithMoveIntf
	// contains filtered or unexported fields
}

OpenStack implements the API wrapper for talking to the OpenStack API

func (*OpenStack) AssignPrivateIP

func (o *OpenStack) AssignPrivateIP(ip net.IP, node *corev1.Node) error

AssignPrivateIP attempts to assigning the IP address provided to the VM instance corresponding to the corev1.Node provided on the cloud the cluster is deployed on. NOTE: This operation is performed against all interfaces that are attached to the server. In case that an instance has 2 interfaces with the same CIDR that this IP address could fit in, the first interface that is found will be used. No guarantees about the correct interface ordering are given in such a case. Throw an AlreadyExistingIPError if the IP provided is already associated with the node, it's up to the caller to decide what to do with that. NOTE: For OpenStack, this is a 2 step operation which is not atomic:

a) Reserve a neutron port.
b) Add the IP address to the allowed_address_pairs field.

If step b) fails, then we will try to undo step a). However, if this undo fails, then we will be in a situation where the user or an upper layer will have to call ReleasePrivateIP to get out of this situation.

func (*OpenStack) GetNodeEgressIPConfiguration

func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)

GetNodeEgressIPConfiguration retrieves the egress IP configuration for the node, following the convention the cloud uses. This means specifically for OpenStack that the interface is keyed by the port's neutron UUID.

func (*OpenStack) MovePrivateIP

func (o *OpenStack) MovePrivateIP(ip net.IP, nodeToAdd, nodeToDel *corev1.Node) error

MovePrivateIP implements moving the IP from one node to another to serve cases like a failover. What's different from calling ReleasePrivateIP followed by AssignPrivateIP is that the reservation Neutron port will not get deleted - MovePrivateIP will only change the allowed_address_pairs on the node's ports to remove IP from nodeToDel and add it to nodeToAdd and update the existing reservation port with the DeviceID of nodeToAdd. Additionally, if reservation port is missing MovePrivateIP will attempt to recreate it (this is a corner case and should not happen in normal operation).

func (*OpenStack) ReleasePrivateIP

func (o *OpenStack) ReleasePrivateIP(ip net.IP, node *corev1.Node) error

ReleasePrivateIP attempts to release the IP address provided from the VM instance corresponding to the corev1.Node provided on the cloud the cluster is deployed on. ReleasePrivateIP must be idempotent, meaning that it will release all matching IP allowed_address_pairs for ports which are bound to this server. It also means that any unbound port on any network that is attached to this server - having the IP address to be released and matching the correct DeviceOwner and DeviceID containing the serverID will be deleted, as well. In OpenStack, it is possible to create different subnets with the exact same CIDR. These different subnets can then be assigned to ports on the same server. Hence, a server could be connected to several ports where the same IP is part of the allowed_address_pairs and where the same IP is reserved in neutron. NOTE: If the IP is non-existant: it returns an NonExistingIPError. The caller will likely want to ignore such an error and continue its normal operation.

Jump to

Keyboard shortcuts

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