mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
107
vendor/k8s.io/kubernetes/pkg/volume/plugins.go
generated
vendored
107
vendor/k8s.io/kubernetes/pkg/volume/plugins.go
generated
vendored
@ -23,6 +23,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/golang/glog"
|
||||
authenticationv1 "k8s.io/api/authentication/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -30,18 +31,29 @@ import (
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||
"k8s.io/kubernetes/pkg/util/io"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume/util/recyclerclient"
|
||||
)
|
||||
|
||||
type ProbeOperation uint32
|
||||
type ProbeEvent struct {
|
||||
Plugin VolumePlugin // VolumePlugin that was added/updated/removed. if ProbeEvent.Op is 'ProbeRemove', Plugin should be nil
|
||||
PluginName string
|
||||
Op ProbeOperation // The operation to the plugin
|
||||
}
|
||||
|
||||
const (
|
||||
// Common parameter which can be specified in StorageClass to specify the desired FSType
|
||||
// Provisioners SHOULD implement support for this if they are block device based
|
||||
// Must be a filesystem type supported by the host operating system.
|
||||
// Ex. "ext4", "xfs", "ntfs". Default value depends on the provisioner
|
||||
VolumeParameterFSType = "fstype"
|
||||
|
||||
ProbeAddOrUpdate ProbeOperation = 1 << iota
|
||||
ProbeRemove
|
||||
)
|
||||
|
||||
// VolumeOptions contains option information about a volume.
|
||||
@ -75,12 +87,8 @@ type VolumeOptions struct {
|
||||
type DynamicPluginProber interface {
|
||||
Init() error
|
||||
|
||||
// If an update has occurred since the last probe, updated = true
|
||||
// and the list of probed plugins is returned.
|
||||
// Otherwise, update = false and probedPlugins = nil.
|
||||
//
|
||||
// If an error occurs, updated and probedPlugins are undefined.
|
||||
Probe() (updated bool, probedPlugins []VolumePlugin, err error)
|
||||
// If an error occurs, events are undefined.
|
||||
Probe() (events []ProbeEvent, err error)
|
||||
}
|
||||
|
||||
// VolumePlugin is an interface to volume plugins that can be used on a
|
||||
@ -209,6 +217,32 @@ type ExpandableVolumePlugin interface {
|
||||
RequiresFSResize() bool
|
||||
}
|
||||
|
||||
// VolumePluginWithAttachLimits is an extended interface of VolumePlugin that restricts number of
|
||||
// volumes that can be attached to a node.
|
||||
type VolumePluginWithAttachLimits interface {
|
||||
VolumePlugin
|
||||
// Return maximum number of volumes that can be attached to a node for this plugin.
|
||||
// The key must be same as string returned by VolumeLimitKey function. The returned
|
||||
// map may look like:
|
||||
// - { "storage-limits-aws-ebs": 39 }
|
||||
// - { "storage-limits-gce-pd": 10 }
|
||||
// A volume plugin may return error from this function - if it can not be used on a given node or not
|
||||
// applicable in given environment (where environment could be cloudprovider or any other dependency)
|
||||
// For example - calling this function for EBS volume plugin on a GCE node should
|
||||
// result in error.
|
||||
// The returned values are stored in node allocatable property and will be used
|
||||
// by scheduler to determine how many pods with volumes can be scheduled on given node.
|
||||
GetVolumeLimits() (map[string]int64, error)
|
||||
// Return volume limit key string to be used in node capacity constraints
|
||||
// The key must start with prefix storage-limits-. For example:
|
||||
// - storage-limits-aws-ebs
|
||||
// - storage-limits-csi-cinder
|
||||
// The key should respect character limit of ResourceName type
|
||||
// This function may be called by kubelet or scheduler to identify node allocatable property
|
||||
// which stores volumes limits.
|
||||
VolumeLimitKey(spec *Spec) string
|
||||
}
|
||||
|
||||
// BlockVolumePlugin is an extend interface of VolumePlugin and is used for block volumes support.
|
||||
type BlockVolumePlugin interface {
|
||||
VolumePlugin
|
||||
@ -242,6 +276,10 @@ type VolumeHost interface {
|
||||
// ex. plugins/kubernetes.io/{PluginName}/{DefaultKubeletVolumeDevicesDirName}/{volumePluginDependentPath}/
|
||||
GetVolumeDevicePluginDir(pluginName string) string
|
||||
|
||||
// GetPodsDir returns the absolute path to a directory where all the pods
|
||||
// information is stored
|
||||
GetPodsDir() string
|
||||
|
||||
// GetPodVolumeDir returns the absolute path a directory which
|
||||
// represents the named volume under the named plugin for the given
|
||||
// pod. If the specified pod does not exist, the result of this call
|
||||
@ -299,6 +337,8 @@ type VolumeHost interface {
|
||||
// Returns a function that returns a configmap.
|
||||
GetConfigMapFunc() func(namespace, name string) (*v1.ConfigMap, error)
|
||||
|
||||
GetServiceAccountTokenFunc() func(namespace, name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error)
|
||||
|
||||
// Returns an interface that should be used to execute any utilities in volume plugins
|
||||
GetExec(pluginName string) mount.Exec
|
||||
|
||||
@ -307,6 +347,9 @@ type VolumeHost interface {
|
||||
|
||||
// Returns the name of the node
|
||||
GetNodeName() types.NodeName
|
||||
|
||||
// Returns the event recorder of kubelet.
|
||||
GetEventRecorder() record.EventRecorder
|
||||
}
|
||||
|
||||
// VolumePluginMgr tracks registered plugins.
|
||||
@ -314,7 +357,7 @@ type VolumePluginMgr struct {
|
||||
mutex sync.Mutex
|
||||
plugins map[string]VolumePlugin
|
||||
prober DynamicPluginProber
|
||||
probedPlugins []VolumePlugin
|
||||
probedPlugins map[string]VolumePlugin
|
||||
Host VolumeHost
|
||||
}
|
||||
|
||||
@ -431,6 +474,9 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPlu
|
||||
if pm.plugins == nil {
|
||||
pm.plugins = map[string]VolumePlugin{}
|
||||
}
|
||||
if pm.probedPlugins == nil {
|
||||
pm.probedPlugins = map[string]VolumePlugin{}
|
||||
}
|
||||
|
||||
allErrs := []error{}
|
||||
for _, plugin := range plugins {
|
||||
@ -544,25 +590,40 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
|
||||
// Check if probedPlugin cache update is required.
|
||||
// If it is, initialize all probed plugins and replace the cache with them.
|
||||
func (pm *VolumePluginMgr) refreshProbedPlugins() {
|
||||
updated, plugins, err := pm.prober.Probe()
|
||||
events, err := pm.prober.Probe()
|
||||
if err != nil {
|
||||
glog.Errorf("Error dynamically probing plugins: %s", err)
|
||||
return // Use cached plugins upon failure.
|
||||
}
|
||||
|
||||
if updated {
|
||||
pm.probedPlugins = []VolumePlugin{}
|
||||
for _, plugin := range plugins {
|
||||
if err := pm.initProbedPlugin(plugin); err != nil {
|
||||
for _, event := range events {
|
||||
if event.Op == ProbeAddOrUpdate {
|
||||
if err := pm.initProbedPlugin(event.Plugin); err != nil {
|
||||
glog.Errorf("Error initializing dynamically probed plugin %s; error: %s",
|
||||
plugin.GetPluginName(), err)
|
||||
event.Plugin.GetPluginName(), err)
|
||||
continue
|
||||
}
|
||||
pm.probedPlugins = append(pm.probedPlugins, plugin)
|
||||
pm.probedPlugins[event.Plugin.GetPluginName()] = event.Plugin
|
||||
} else if event.Op == ProbeRemove {
|
||||
delete(pm.probedPlugins, event.Plugin.GetPluginName())
|
||||
} else {
|
||||
glog.Errorf("Unknown Operation on PluginName: %s.",
|
||||
event.Plugin.GetPluginName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ListVolumePluginWithLimits returns plugins that have volume limits on nodes
|
||||
func (pm *VolumePluginMgr) ListVolumePluginWithLimits() []VolumePluginWithAttachLimits {
|
||||
matchedPlugins := []VolumePluginWithAttachLimits{}
|
||||
for _, v := range pm.plugins {
|
||||
if plugin, ok := v.(VolumePluginWithAttachLimits); ok {
|
||||
matchedPlugins = append(matchedPlugins, plugin)
|
||||
}
|
||||
}
|
||||
return matchedPlugins
|
||||
}
|
||||
|
||||
// FindPersistentPluginBySpec looks for a persistent volume plugin that can
|
||||
// support a given volume specification. If no plugin is found, return an
|
||||
// error
|
||||
@ -577,6 +638,20 @@ func (pm *VolumePluginMgr) FindPersistentPluginBySpec(spec *Spec) (PersistentVol
|
||||
return nil, fmt.Errorf("no persistent volume plugin matched")
|
||||
}
|
||||
|
||||
// FindVolumePluginWithLimitsBySpec returns volume plugin that has a limit on how many
|
||||
// of them can be attached to a node
|
||||
func (pm *VolumePluginMgr) FindVolumePluginWithLimitsBySpec(spec *Spec) (VolumePluginWithAttachLimits, error) {
|
||||
volumePlugin, err := pm.FindPluginBySpec(spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not find volume plugin for spec : %#v", spec)
|
||||
}
|
||||
|
||||
if limitedPlugin, ok := volumePlugin.(VolumePluginWithAttachLimits); ok {
|
||||
return limitedPlugin, nil
|
||||
}
|
||||
return nil, fmt.Errorf("no plugin with limits found")
|
||||
}
|
||||
|
||||
// FindPersistentPluginByName fetches a persistent volume plugin by name. If
|
||||
// no plugin is found, returns error.
|
||||
func (pm *VolumePluginMgr) FindPersistentPluginByName(name string) (PersistentVolumePlugin, error) {
|
||||
@ -803,5 +878,5 @@ func ValidateRecyclerPodTemplate(pod *v1.Pod) error {
|
||||
|
||||
type dummyPluginProber struct{}
|
||||
|
||||
func (*dummyPluginProber) Init() error { return nil }
|
||||
func (*dummyPluginProber) Probe() (bool, []VolumePlugin, error) { return false, nil, nil }
|
||||
func (*dummyPluginProber) Init() error { return nil }
|
||||
func (*dummyPluginProber) Probe() ([]ProbeEvent, error) { return nil, nil }
|
||||
|
Reference in New Issue
Block a user