common

package
v0.0.0-...-5da5385 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AnnProvisionedBy is the external provisioner annotation in PV object
	AnnProvisionedBy = "pv.kubernetes.io/provisioned-by"
	// NodeLabelKey is the label key that this provisioner uses for PV node affinity
	// hostname is not the best choice, but it's what pod and node affinity also use
	NodeLabelKey = apis.LabelHostname

	// DefaultBlockCleanerCommand is the default block device cleaning command
	DefaultBlockCleanerCommand = "/scripts/quick_reset.sh"

	// EventVolumeFailedDelete copied from k8s.io/kubernetes/pkg/controller/volume/events
	EventVolumeFailedDelete = "VolumeFailedDelete"
	// ProvisionerConfigPath points to the path inside of the provisioner container where configMap volume is mounted
	ProvisionerConfigPath = "/etc/provisioner/config/"
	// ProvisonerStorageClassConfig defines file name of the file which stores storage class
	// configuration. The file name must match to the key name used in configuration map.
	ProvisonerStorageClassConfig = "storageClassMap"
	// ProvisionerNodeLabelsForPV contains a list of node labels to be copied to the PVs created by the provisioner
	ProvisionerNodeLabelsForPV = "nodeLabelsForPV"
	// ProvisionerUseAlphaAPI shows if we need to use alpha API, default to false
	ProvisionerUseAlphaAPI = "useAlphaAPI"
	// AlphaStorageNodeAffinityAnnotation defines node affinity policies for a PersistentVolume.
	// Value is a string of the json representation of type NodeAffinity
	AlphaStorageNodeAffinityAnnotation = "volume.alpha.kubernetes.io/node-affinity"
	// VolumeDelete copied from k8s.io/kubernetes/pkg/controller/volume/events
	VolumeDelete = "VolumeDelete"

	// LocalPVEnv will contain the device path when script is invoked
	LocalPVEnv = "LOCAL_PV_BLKDEVICE"
	// LocalFilesystemEnv will contain the filesystm path when script is invoked
	LocalFilesystemEnv = "LOCAL_PV_FILESYSTEM"
	// KubeConfigEnv will (optionally) specify the location of kubeconfig file on the node.
	KubeConfigEnv = "KUBECONFIG"

	// NodeNameLabel is the name of the label that holds the nodename
	NodeNameLabel = "kubernetes.io/hostname"

	// DefaultVolumeMode is the default volume mode of created PV object.
	DefaultVolumeMode = "Filesystem"
)

Variables

View Source
var BuildConfigFromFlags = clientcmd.BuildConfigFromFlags

BuildConfigFromFlags being defined to enable mocking during unit testing

View Source
var InClusterConfig = rest.InClusterConfig

InClusterConfig being defined to enable mocking during unit testing

Functions

func ConfigMapDataToVolumeConfig

func ConfigMapDataToVolumeConfig(data map[string]string, provisionerConfig *ProvisionerConfiguration) error

ConfigMapDataToVolumeConfig converts configmap data to volume config.

func CreateLocalPVSpec

func CreateLocalPVSpec(config *LocalPVConfig) *v1.PersistentVolume

CreateLocalPVSpec returns a PV spec that can be used for PV creation

func GenerateMountName

func GenerateMountName(mount *MountConfig) string

GenerateMountName generates a volumeMount.name for pod spec, based on volume configuration.

func GetContainerPath

func GetContainerPath(pv *v1.PersistentVolume, config MountConfig) (string, error)

GetContainerPath gets the local path (within provisioner container) of the PV

func GetVolumeConfigFromConfigMap

func GetVolumeConfigFromConfigMap(client *kubernetes.Clientset, namespace, name string, provisionerConfig *ProvisionerConfiguration) error

GetVolumeConfigFromConfigMap gets volume configuration from given configmap.

func GetVolumeMode

func GetVolumeMode(volUtil util.VolumeUtil, fullPath string) (v1.PersistentVolumeMode, error)

GetVolumeMode check volume mode of given path.

func LoadProvisionerConfigs

func LoadProvisionerConfigs(configPath string, provisionerConfig *ProvisionerConfiguration) error

LoadProvisionerConfigs loads all configuration into a string and unmarshal it into ProvisionerConfiguration struct. The configuration is stored in the configmap which is mounted as a volume.

func SetupClient

func SetupClient() *kubernetes.Clientset

SetupClient created client using either in-cluster configuration or if KUBECONFIG environment variable is specified then using that config.

func VolumeConfigToConfigMapData

func VolumeConfigToConfigMapData(config *ProvisionerConfiguration) (map[string]string, error)

VolumeConfigToConfigMapData converts volume config to configmap data.

Types

type LocalPVConfig

type LocalPVConfig struct {
	Name            string
	HostPath        string
	Capacity        int64
	StorageClass    string
	ReclaimPolicy   v1.PersistentVolumeReclaimPolicy
	ProvisionerName string
	UseAlphaAPI     bool
	AffinityAnn     string
	NodeAffinity    *v1.VolumeNodeAffinity
	VolumeMode      v1.PersistentVolumeMode
	MountOptions    []string
	FsType          *string
	Labels          map[string]string
}

LocalPVConfig defines the parameters for creating a local PV

type MountConfig

type MountConfig struct {
	// The hostpath directory
	HostDir string `json:"hostDir" yaml:"hostDir"`
	// The mount point of the hostpath volume
	MountDir string `json:"mountDir" yaml:"mountDir"`
	// The type of block cleaner to use
	BlockCleanerCommand []string `json:"blockCleanerCommand" yaml:"blockCleanerCommand"`
	// The volume mode of created PersistentVolume object,
	// default to Filesystem if not specified.
	VolumeMode string `json:"volumeMode" yaml:"volumeMode"`
	// Filesystem type to mount.
	// It applies only when the source path is a block device,
	// and desire volume mode is Filesystem.
	// Must be a filesystem type supported by the host operating system.
	FsType string `json:"fsType" yaml:"fsType"`
}

MountConfig stores a configuration for discoverying a specific storageclass

type ProvisionerConfiguration

type ProvisionerConfiguration struct {
	// StorageClassConfig defines configuration of Provisioner's storage classes
	StorageClassConfig map[string]MountConfig `json:"storageClassMap" yaml:"storageClassMap"`
	// NodeLabelsForPV contains a list of node labels to be copied to the PVs created by the provisioner
	// +optional
	NodeLabelsForPV []string `json:"nodeLabelsForPV" yaml:"nodeLabelsForPV"`
	// UseAlphaAPI shows if we need to use alpha API, default to false
	UseAlphaAPI bool `json:"useAlphaAPI" yaml:"useAlphaAPI"`
	// UseJobForCleaning indicates if Jobs should be spawned for cleaning block devices (as opposed to process),
	// default is false.
	// +optional
	UseJobForCleaning bool `json:"useJobForCleaning" yaml:"useJobForCleaning"`
	// MinResyncPeriod is minimum resync period. Resync period in reflectors
	// will be random between MinResyncPeriod and 2*MinResyncPeriod.
	MinResyncPeriod metav1.Duration `json:"minResyncPeriod" yaml:"minResyncPeriod"`
	// UseNodeNameOnly indicates if Node.Name should be used in the provisioner name
	// instead of Node.UID. Default is false.
	// +optional
	UseNodeNameOnly bool `json:"useNodeNameOnly" yaml:"useNodeNameOnly"`
}

ProvisionerConfiguration defines Provisioner configuration objects Each configuration key of the struct e.g StorageClassConfig is individually marshaled in VolumeConfigToConfigMapData. TODO Need to find a way to marshal the struct more efficiently.

type RuntimeConfig

type RuntimeConfig struct {
	*UserConfig
	// Unique name of this provisioner
	Name string
	// K8s API client
	Client kubernetes.Interface
	// Cache to store PVs managed by this provisioner
	Cache *cache.VolumeCache
	// K8s API layer
	APIUtil util.APIUtil
	// Volume util layer
	VolUtil util.VolumeUtil
	// Recorder is used to record events in the API server
	Recorder record.EventRecorder
	// Disable block device discovery and management if true
	BlockDisabled bool
	// Mounter used to verify mountpoints
	Mounter mount.Interface
	// InformerFactory gives access to informers for the controller.
	InformerFactory informers.SharedInformerFactory
}

RuntimeConfig stores all the objects that the provisioner needs to run

type UserConfig

type UserConfig struct {
	// Node object for this node
	Node *v1.Node
	// key = storageclass, value = mount configuration for the storageclass
	DiscoveryMap map[string]MountConfig
	// Labels and their values that are added to PVs created by the provisioner
	NodeLabelsForPV []string
	// UseAlphaAPI shows if we need to use alpha API
	UseAlphaAPI bool
	// UseJobForCleaning indicates if Jobs should be spawned for cleaning block devices (as opposed to process),.
	UseJobForCleaning bool
	// Namespace of this Pod (optional)
	Namespace string
	// JobContainerImage of container to use for jobs (optional)
	JobContainerImage string
	// MinResyncPeriod is minimum resync period. Resync period in reflectors
	// will be random between MinResyncPeriod and 2*MinResyncPeriod.
	MinResyncPeriod metav1.Duration
	// UseNodeNameOnly indicates if Node.Name should be used in the provisioner name
	// instead of Node.UID.
	UseNodeNameOnly bool
}

UserConfig stores all the user-defined parameters to the provisioner

Jump to

Keyboard shortcuts

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