vsphere

package
v0.0.0-...-d88c8b5 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CredentialsNotFoundErrMsg = "Credentials not found"
	CredentialMissingErrMsg   = "Username/Password is missing"
	UnknownSecretKeyErrMsg    = "Unknown secret key"
)

Error Messages

View Source
const (
	POOL_SIZE  = 8
	QUEUE_SIZE = POOL_SIZE * 10
)

TODO: Make it configurable in vsphere.conf

View Source
const (
	ProviderName                  = "vsphere"
	VolDir                        = "kubevols"
	RoundTripperDefaultCount      = 3
	DummyVMPrefixName             = "vsphere-k8s"
	CleanUpDummyVMRoutineInterval = 5
)

VSphere Cloud Provider constants

View Source
const (
	MissingUsernameErrMsg = "Username is missing"
	MissingPasswordErrMsg = "Password is missing"
	NoZoneTagInVCErrMsg   = "No zone tags found in vCenter"
)

Error Messages

View Source
const (
	DatastoreProperty     = "datastore"
	DatastoreInfoProperty = "info"
	DatastoreNameProperty = "name"
	Folder                = "Folder"
	VirtualMachine        = "VirtualMachine"
	DummyDiskName         = "kube-dummyDisk.vmdk"
	ProviderPrefix        = "vsphere://"

	UUIDPrefix = "VMware-"
)
View Source
const UUIDPath = "/sys/class/dmi/id/product_serial"

Variables

View Source
var (
	ErrCredentialsNotFound = errors.New(CredentialsNotFoundErrMsg)
	ErrCredentialMissing   = errors.New(CredentialMissingErrMsg)
	ErrUnknownSecretKey    = errors.New(UnknownSecretKeyErrMsg)
)

Error constants

View Source
var (
	ErrUsernameMissing = errors.New(MissingUsernameErrMsg)
	ErrPasswordMissing = errors.New(MissingPasswordErrMsg)
	ErrNoZoneTagInVC   = errors.New(NoZoneTagInVCErrMsg)
)

Error constants

Functions

func GetNodeUUID

func GetNodeUUID(node *v1.Node) (string, error)

func GetUUIDFromProviderID

func GetUUIDFromProviderID(providerID string) string

func GetVMUUID

func GetVMUUID() (string, error)

func IsUUIDSupportedNode

func IsUUIDSupportedNode(node *v1.Node) (bool, error)

Types

type Credential

type Credential struct {
	User     string `gcfg:"user"`
	Password string `gcfg:"password" datapolicy:"password"`
}

type NodeDetails

type NodeDetails struct {
	NodeName string

	VMUUID string
	Zone   *cloudprovider.Zone
	// contains filtered or unexported fields
}

type NodeInfo

type NodeInfo struct {
	// contains filtered or unexported fields
}

Stores info about the kubernetes node

func (NodeInfo) String

func (n NodeInfo) String() string

func (*NodeInfo) VM

func (nodeInfo *NodeInfo) VM() *vclib.VirtualMachine

type NodeManager

type NodeManager struct {
	// contains filtered or unexported fields
}

func (*NodeManager) CredentialManager

func (nm *NodeManager) CredentialManager() *SecretCredentialManager

func (*NodeManager) DiscoverNode

func (nm *NodeManager) DiscoverNode(node *v1.Node) error

func (*NodeManager) GetHostsInZone

func (nm *NodeManager) GetHostsInZone(ctx context.Context, zoneFailureDomain string) ([]*object.HostSystem, error)

func (*NodeManager) GetNode

func (nm *NodeManager) GetNode(nodeName k8stypes.NodeName) (v1.Node, error)

func (*NodeManager) GetNodeDetails

func (nm *NodeManager) GetNodeDetails() ([]NodeDetails, error)

GetNodeDetails returns NodeDetails for all the discovered nodes.

This method is a getter but it can cause side-effect of updating NodeInfo objects.

func (*NodeManager) GetNodeInfo

func (nm *NodeManager) GetNodeInfo(nodeName k8stypes.NodeName) (NodeInfo, error)

GetNodeInfo returns a NodeInfo which datacenter, vm and vc server ip address. This method returns an error if it is unable find node VCs and DCs listed in vSphere.conf NodeInfo returned may not be updated to reflect current VM location.

This method is a getter but it can cause side-effect of updating NodeInfo object.

func (*NodeManager) GetNodeInfoWithNodeObject

func (nm *NodeManager) GetNodeInfoWithNodeObject(node *v1.Node) (NodeInfo, error)

GetNodeInfoWithNodeObject returns a NodeInfo which datacenter, vm and vc server ip address. This method returns an error if it is unable find node VCs and DCs listed in vSphere.conf NodeInfo returned may not be updated to reflect current VM location.

This method is a getter but it can cause side-effect of updating NodeInfo object.

func (*NodeManager) GetVSphereInstance

func (nm *NodeManager) GetVSphereInstance(nodeName k8stypes.NodeName) (VSphereInstance, error)

func (*NodeManager) RediscoverNode

func (nm *NodeManager) RediscoverNode(nodeName k8stypes.NodeName) error

func (*NodeManager) RegisterNode

func (nm *NodeManager) RegisterNode(node *v1.Node) error

func (*NodeManager) UnRegisterNode

func (nm *NodeManager) UnRegisterNode(node *v1.Node) error

func (*NodeManager) UpdateCredentialManager

func (nm *NodeManager) UpdateCredentialManager(credentialManager *SecretCredentialManager)

type SecretCache

type SecretCache struct {
	VirtualCenter map[string]*Credential
	Secret        *corev1.Secret
	// contains filtered or unexported fields
}

func (*SecretCache) GetCredential

func (cache *SecretCache) GetCredential(server string) (Credential, bool)

func (*SecretCache) GetSecret

func (cache *SecretCache) GetSecret() *corev1.Secret

func (*SecretCache) UpdateSecret

func (cache *SecretCache) UpdateSecret(secret *corev1.Secret)

type SecretCredentialManager

type SecretCredentialManager struct {
	SecretName      string
	SecretNamespace string
	SecretLister    v1.SecretLister
	Cache           *SecretCache
}

func (*SecretCredentialManager) GetCredential

func (secretCredentialManager *SecretCredentialManager) GetCredential(server string) (*Credential, error)

GetCredential returns credentials for the given vCenter Server. GetCredential returns error if Secret is not added. GetCredential return error is the secret doesn't contain any credentials.

type VSphere

type VSphere struct {
	// contains filtered or unexported fields
}

VSphere is an implementation of cloud provider Interface for VSphere.

func GetVSphere

func GetVSphere() (*VSphere, error)

GetVSphere reads vSphere configuration from system environment and construct vSphere object

func (*VSphere) AddSSHKeyToAllInstances

func (vs *VSphere) AddSSHKeyToAllInstances(ctx context.Context, user string, keyData []byte) error

AddSSHKeyToAllInstances add SSH key to all instances

func (*VSphere) AttachDisk

func (vs *VSphere) AttachDisk(vmDiskPath string, storagePolicyName string, nodeName k8stypes.NodeName) (diskUUID string, err error)

AttachDisk attaches given virtual disk volume to the compute running kubelet.

func (*VSphere) Clusters

func (vs *VSphere) Clusters() (cloudprovider.Clusters, bool)

func (*VSphere) CreateVolume

func (vs *VSphere) CreateVolume(volumeOptions *vclib.VolumeOptions) (canonicalVolumePath string, err error)

CreateVolume creates a volume of given size (in KiB) and return the volume path. If the volumeOptions.Datastore is part of datastore cluster for example - DatastoreCluster/sharedVmfs-0 then return value will be DatastoreCluster/sharedVmfs-0 kubevols/<volume-name>.vmdk else return value will be [sharedVmfs-0] kubevols/<volume-name>.vmdk

func (*VSphere) CurrentNodeName

func (vs *VSphere) CurrentNodeName(ctx context.Context, hostname string) (k8stypes.NodeName, error)

CurrentNodeName gives the current node name

func (*VSphere) DeleteVolume

func (vs *VSphere) DeleteVolume(vmDiskPath string) error

DeleteVolume deletes a volume given volume name.

func (*VSphere) DetachDisk

func (vs *VSphere) DetachDisk(volPath string, nodeName k8stypes.NodeName) error

DetachDisk detaches given virtual disk volume from the compute running kubelet.

func (*VSphere) DiskIsAttached

func (vs *VSphere) DiskIsAttached(volPath string, nodeName k8stypes.NodeName) (bool, string, error)

DiskIsAttached returns if disk is attached to the VM using controllers supported by the plugin.

func (*VSphere) DisksAreAttached

func (vs *VSphere) DisksAreAttached(nodeVolumes map[k8stypes.NodeName][]string) (map[k8stypes.NodeName]map[string]bool, error)

DisksAreAttached returns if disks are attached to the VM using controllers supported by the plugin. 1. Converts volPaths into canonical form so that it can be compared with the VM device path. 2. Segregates nodes by vCenter and Datacenter they are present in. This reduces calls to VC. 3. Creates go routines per VC-DC to find whether disks are attached to the nodes. 4. If the some of the VMs are not found or migrated then they are added to a list. 5. After successful execution of goroutines, 5a. If there are any VMs which needs to be retried, they are rediscovered and the whole operation is initiated again for only rediscovered VMs. 5b. If VMs are removed from vSphere inventory they are ignored.

func (*VSphere) FindDatastoreByName

func (vs *VSphere) FindDatastoreByName(ctx context.Context, datastoreName string) ([]*vclib.DatastoreInfo, error)

FindDatastoreByName looks for the given datastore by name across all available datacenters. If more than one Datacenter has a Datastore with the given name, then returns reference to all of them.

func (*VSphere) GetLabelsForVolume

func (vs *VSphere) GetLabelsForVolume(ctx context.Context, pv *v1.PersistentVolume) (map[string]string, error)

GetLabelsForVolume implements the PVLabeler interface for VSphere since this interface is used by the PV label admission controller.

func (*VSphere) GetNodeNameFromProviderID

func (vs *VSphere) GetNodeNameFromProviderID(providerID string) (string, error)

func (*VSphere) GetVolumeLabels

func (vs *VSphere) GetVolumeLabels(volumePath string) (map[string]string, error)

GetVolumeLabels returns the well known zone and region labels for given volume

func (*VSphere) GetWorkspaceDatacenters

func (vs *VSphere) GetWorkspaceDatacenters(ctx context.Context) ([]*vclib.Datacenter, error)

GetWorkspaceDatacenters returns the Datacenter objects that VCP has access to. User can configure the list of datacenters in vsphere.conf. Otherwise all the Datacenters in the configured list of VCs are returned.

func (*VSphere) GetZone

func (vs *VSphere) GetZone(ctx context.Context) (cloudprovider.Zone, error)

GetZone implements Zones.GetZone

func (*VSphere) GetZoneByNodeName

func (vs *VSphere) GetZoneByNodeName(ctx context.Context, nodeName k8stypes.NodeName) (cloudprovider.Zone, error)

func (*VSphere) GetZoneByProviderID

func (vs *VSphere) GetZoneByProviderID(ctx context.Context, providerID string) (cloudprovider.Zone, error)

func (*VSphere) GetZoneToHosts

GetZoneToHosts returns a map of 'zone' -> 'list of hosts in that zone' in given VC

func (*VSphere) GetZonesForDatastore

func (vs *VSphere) GetZonesForDatastore(ctx context.Context, datastore *vclib.Datastore) ([]cloudprovider.Zone, error)

GetZonesForDatastore returns all the zones from which this datastore is visible

func (*VSphere) HasClusterID

func (vs *VSphere) HasClusterID() bool

HasClusterID returns true if the cluster has a clusterID

func (*VSphere) Initialize

func (vs *VSphere) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{})

Initialize passes a Kubernetes clientBuilder interface to the cloud provider

func (*VSphere) InstanceExistsByProviderID

func (vs *VSphere) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error)

InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.

func (*VSphere) InstanceID

func (vs *VSphere) InstanceID(ctx context.Context, nodeName k8stypes.NodeName) (string, error)

InstanceID returns the cloud provider ID of the node with the specified Name.

func (*VSphere) InstanceShutdownByProviderID

func (vs *VSphere) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error)

InstanceShutdownByProviderID returns true if the instance is in safe state to detach volumes

func (*VSphere) InstanceType

func (vs *VSphere) InstanceType(ctx context.Context, name k8stypes.NodeName) (string, error)

func (*VSphere) InstanceTypeByProviderID

func (vs *VSphere) InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error)

InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID This method will not be called from the node that is requesting this ID. i.e. metadata service and other local methods cannot be used here

func (*VSphere) Instances

func (vs *VSphere) Instances() (cloudprovider.Instances, bool)

Instances returns an implementation of Instances for vSphere.

func (*VSphere) InstancesV2

func (vs *VSphere) InstancesV2() (cloudprovider.InstancesV2, bool)

InstancesV2 returns an implementation of InstancesV2 for vSphere. TODO: implement ONLY for external cloud provider

func (*VSphere) LoadBalancer

func (vs *VSphere) LoadBalancer() (cloudprovider.LoadBalancer, bool)

LoadBalancer returns an implementation of LoadBalancer for vSphere.

func (*VSphere) NodeAdded

func (vs *VSphere) NodeAdded(obj interface{})

Notification handler when node is added into k8s cluster.

func (*VSphere) NodeAddresses

func (vs *VSphere) NodeAddresses(ctx context.Context, nodeName k8stypes.NodeName) ([]v1.NodeAddress, error)

NodeAddresses is an implementation of Instances.NodeAddresses.

func (*VSphere) NodeAddressesByProviderID

func (vs *VSphere) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]v1.NodeAddress, error)

NodeAddressesByProviderID returns the node addresses of an instances with the specified unique providerID This method will not be called from the node that is requesting this ID. i.e. metadata service and other local methods cannot be used here

func (*VSphere) NodeDeleted

func (vs *VSphere) NodeDeleted(obj interface{})

Notification handler when node is removed from k8s cluster.

func (*VSphere) NodeManager

func (vs *VSphere) NodeManager() (nodeManager *NodeManager)

func (*VSphere) ProviderName

func (vs *VSphere) ProviderName() string

ProviderName returns the cloud provider ID.

func (*VSphere) Routes

func (vs *VSphere) Routes() (cloudprovider.Routes, bool)

Routes returns a false since the interface is not supported for vSphere.

func (*VSphere) SecretAdded

func (vs *VSphere) SecretAdded(obj interface{})

Notification handler when credentials secret is added.

func (*VSphere) SecretUpdated

func (vs *VSphere) SecretUpdated(obj interface{}, newObj interface{})

Notification handler when credentials secret is updated.

func (*VSphere) SetInformers

func (vs *VSphere) SetInformers(informerFactory informers.SharedInformerFactory)

Initialize Node Informers

func (*VSphere) Zones

func (vs *VSphere) Zones() (cloudprovider.Zones, bool)

Zones returns an implementation of Zones for vSphere.

type VSphereConfig

type VSphereConfig struct {
	Global struct {
		// vCenter username.
		User string `gcfg:"user"`
		// vCenter password in clear text.
		Password string `gcfg:"password" datapolicy:"password"`
		// Deprecated. Use VirtualCenter to specify multiple vCenter Servers.
		// vCenter IP.
		VCenterIP string `gcfg:"server"`
		// vCenter port.
		VCenterPort string `gcfg:"port"`
		// True if vCenter uses self-signed cert.
		InsecureFlag bool `gcfg:"insecure-flag"`
		// Specifies the path to a CA certificate in PEM format. Optional; if not
		// configured, the system's CA certificates will be used.
		CAFile string `gcfg:"ca-file"`
		// Thumbprint of the VCenter's certificate thumbprint
		Thumbprint string `gcfg:"thumbprint"`
		// Datacenter in which VMs are located.
		// Deprecated. Use "datacenters" instead.
		Datacenter string `gcfg:"datacenter"`
		// Datacenter in which VMs are located.
		Datacenters string `gcfg:"datacenters"`
		// Datastore in which vmdks are stored.
		// Deprecated. See Workspace.DefaultDatastore
		DefaultDatastore string `gcfg:"datastore"`
		// WorkingDir is path where VMs can be found. Also used to create dummy VMs.
		// Deprecated.
		WorkingDir string `gcfg:"working-dir"`
		// Soap round tripper count (retries = RoundTripper - 1)
		RoundTripperCount uint `gcfg:"soap-roundtrip-count"`
		// Is required on the controller-manager if it does not run on a VMware machine
		// VMUUID is the VM Instance UUID of virtual machine which can be retrieved from instanceUuid
		// property in VmConfigInfo, or also set as vc.uuid in VMX file.
		// If not set, will be fetched from the machine via sysfs (requires root)
		VMUUID string `gcfg:"vm-uuid"`
		// Deprecated as virtual machine will be automatically discovered.
		// VMName is the VM name of virtual machine
		// Combining the WorkingDir and VMName can form a unique InstanceID.
		// When vm-name is set, no username/password is required on worker nodes.
		VMName string `gcfg:"vm-name"`
		// Name of the secret were vCenter credentials are present.
		SecretName string `gcfg:"secret-name"`
		// Secret Namespace where secret will be present that has vCenter credentials.
		SecretNamespace string `gcfg:"secret-namespace"`
		// Secret changes being ingnored for cloud resources
		SecretNotManaged bool `gcfg:"secret-not-managed"`
	}

	VirtualCenter map[string]*VirtualCenterConfig

	Network struct {
		// PublicNetwork is name of the network the VMs are joined to.
		PublicNetwork string `gcfg:"public-network"`
	}

	Disk struct {
		// SCSIControllerType defines SCSI controller to be used.
		SCSIControllerType string `dcfg:"scsicontrollertype"`
	}

	// Endpoint used to create volumes
	Workspace struct {
		VCenterIP        string `gcfg:"server"`
		Datacenter       string `gcfg:"datacenter"`
		Folder           string `gcfg:"folder"`
		DefaultDatastore string `gcfg:"default-datastore"`
		ResourcePoolPath string `gcfg:"resourcepool-path"`
	}

	// Tag categories and tags which correspond to "built-in node labels: zones and region"
	Labels struct {
		Zone   string `gcfg:"zone"`
		Region string `gcfg:"region"`
	}
}

Structure that represents the content of vsphere.conf file. Users specify the configuration of one or more Virtual Centers in vsphere.conf where the Kubernetes master and worker nodes are running. NOTE: Cloud config files should follow the same Kubernetes deprecation policy as flags or CLIs. Config fields should not change behavior in incompatible ways and should be deprecated for at least 2 release prior to removing. See https://kubernetes.io/docs/reference/using-api/deprecation-policy/#deprecating-a-flag-or-cli for more details.

type VSphereInstance

type VSphereInstance struct {
	// contains filtered or unexported fields
}

Represents a vSphere instance where one or more kubernetes nodes are running.

type VirtualCenterConfig

type VirtualCenterConfig struct {
	// vCenter username.
	User string `gcfg:"user"`
	// vCenter password in clear text.
	Password string `gcfg:"password" datapolicy:"password"`
	// vCenter port.
	VCenterPort string `gcfg:"port"`
	// Datacenter in which VMs are located.
	Datacenters string `gcfg:"datacenters"`
	// Soap round tripper count (retries = RoundTripper - 1)
	RoundTripperCount uint `gcfg:"soap-roundtrip-count"`
	// Thumbprint of the VCenter's certificate thumbprint
	Thumbprint string `gcfg:"thumbprint"`
}

Structure that represents Virtual Center configuration

type Volumes

type Volumes interface {
	// AttachDisk attaches given disk to given node. Current node
	// is used when nodeName is empty string.
	AttachDisk(vmDiskPath string, storagePolicyName string, nodeName k8stypes.NodeName) (diskUUID string, err error)

	// DetachDisk detaches given disk to given node. Current node
	// is used when nodeName is empty string.
	// Assumption: If node doesn't exist, disk is already detached from node.
	DetachDisk(volPath string, nodeName k8stypes.NodeName) error

	// DiskIsAttached checks if a disk is attached to the given node.
	// Assumption: If node doesn't exist, disk is not attached to the node.
	DiskIsAttached(volPath string, nodeName k8stypes.NodeName) (bool, string, error)

	// DisksAreAttached checks if a list disks are attached to the given node.
	// Assumption: If node doesn't exist, disks are not attached to the node.
	DisksAreAttached(nodeVolumes map[k8stypes.NodeName][]string) (map[k8stypes.NodeName]map[string]bool, error)

	// CreateVolume creates a new vmdk with specified parameters.
	CreateVolume(volumeOptions *vclib.VolumeOptions) (volumePath string, err error)

	// DeleteVolume deletes vmdk.
	DeleteVolume(vmDiskPath string) error
}

type VsphereVolumeMap

type VsphereVolumeMap struct {
	// contains filtered or unexported fields
}

VsphereVolumeMap stores last known state of node and volume mapping

func NewVsphereVolumeMap

func NewVsphereVolumeMap() *VsphereVolumeMap

func (*VsphereVolumeMap) Add

func (vsphereVolume *VsphereVolumeMap) Add(node k8stypes.NodeName, vmDevices object.VirtualDeviceList)

Add all devices found on a node to the device map

func (*VsphereVolumeMap) CheckForVolume

func (vsphereVolume *VsphereVolumeMap) CheckForVolume(path string) (k8stypes.NodeName, bool)

CheckForVolume verifies if disk is attached to some node in the cluster. This check is not definitive and should be followed up by separate verification.

func (*VsphereVolumeMap) RemoveUnverified

func (vsphereVolume *VsphereVolumeMap) RemoveUnverified()

RemoveUnverified will remove any device which we could not verify to be attached to a node.

func (*VsphereVolumeMap) StartDiskVerification

func (vsphereVolume *VsphereVolumeMap) StartDiskVerification()

StartDiskVerification marks all known volumes as unverified so as disks which aren't verified can be removed at the end of verification process

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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