controller

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultResyncPeriod is used when option function ResyncPeriod is omitted
	DefaultResyncPeriod = 15 * time.Minute
	// DefaultThreadiness is used when option function Threadiness is omitted
	DefaultThreadiness = 4
	// DefaultExponentialBackOffOnError is used when option function ExponentialBackOffOnError is omitted
	DefaultExponentialBackOffOnError = true
	// DefaultCreateProvisionedPVRetryCount is used when option function CreateProvisionedPVRetryCount is omitted
	DefaultCreateProvisionedPVRetryCount = 5
	// DefaultCreateProvisionedPVInterval is used when option function CreateProvisionedPVInterval is omitted
	DefaultCreateProvisionedPVInterval = 10 * time.Second
	// DefaultFailedProvisionThreshold is used when option function FailedProvisionThreshold is omitted
	DefaultFailedProvisionThreshold = 15
	// DefaultFailedDeleteThreshold is used when option function FailedDeleteThreshold is omitted
	DefaultFailedDeleteThreshold = 15
	// DefaultLeaderElection is used when option function LeaderElection is omitted
	DefaultLeaderElection = true
	// DefaultLeaseDuration is used when option function LeaseDuration is omitted
	DefaultLeaseDuration = 15 * time.Second
	// DefaultRenewDeadline is used when option function RenewDeadline is omitted
	DefaultRenewDeadline = 10 * time.Second
	// DefaultRetryPeriod is used when option function RetryPeriod is omitted
	DefaultRetryPeriod = 2 * time.Second
	// DefaultMetricsPort is used when option function MetricsPort is omitted
	DefaultMetricsPort = 0
	// DefaultMetricsAddress is used when option function MetricsAddress is omitted
	DefaultMetricsAddress = "0.0.0.0"
	// DefaultMetricsPath is used when option function MetricsPath is omitted
	DefaultMetricsPath = "/metrics"
	// DefaultAddFinalizer is used when option function AddFinalizer is omitted
	DefaultAddFinalizer = false
)

Variables

This section is empty.

Functions

func AddFinalizer

func AddFinalizer(addFinalizer bool) func(*ProvisionController) error

AddFinalizer determines whether to add a finalizer marking the provisioner as the owner of the PV with clean up duty. A PV having the finalizer means the provisioner wants to keep it around so that it can reclaim it.

func AdditionalProvisionerNames

func AdditionalProvisionerNames(additionalProvisionerNames []string) func(*ProvisionController) error

AdditionalProvisionerNames sets additional names for the provisioner

func ClaimsInformer

func ClaimsInformer(informer cache.SharedIndexInformer) func(*ProvisionController) error

ClaimsInformer sets the informer to use for accessing PersistentVolumeClaims. Defaults to using a internal informer.

func ClassesInformer

func ClassesInformer(informer cache.SharedInformer) func(*ProvisionController) error

ClassesInformer sets the informer to use for accessing StorageClasses. The informer must use the versioned resource appropriate for the Kubernetes cluster version (that is, v1.StorageClass for >= 1.6, and v1beta1.StorageClass for < 1.6). Defaults to using a internal informer.

func CreateProvisionedPVBackoff

func CreateProvisionedPVBackoff(backoff wait.Backoff) func(*ProvisionController) error

CreateProvisionedPVBackoff is the configuration of exponential backoff between retries when we create a PV object for a provisioned volume. Defaults to linear backoff, 10 seconds 5 times. If PV is not saved after given number of retries, corresponding storage asset (volume) is deleted! Only one of CreateProvisionedPVInterval+CreateProvisionedPVRetryCount or CreateProvisionedPVBackoff or CreateProvisionedPVLimiter can be used. Deprecated: Use CreateProvisionedPVLimiter instead, it tries indefinitely.

func CreateProvisionedPVInterval

func CreateProvisionedPVInterval(createProvisionedPVInterval time.Duration) func(*ProvisionController) error

CreateProvisionedPVInterval is the interval between retries when we create a PV object for a provisioned volume. Defaults to 10 seconds. If PV is not saved after given number of retries, corresponding storage asset (volume) is deleted! Only one of CreateProvisionedPVInterval+CreateProvisionedPVRetryCount or CreateProvisionedPVBackoff or CreateProvisionedPVLimiter can be used. Deprecated: Use CreateProvisionedPVLimiter instead, it tries indefinitely.

func CreateProvisionedPVLimiter

func CreateProvisionedPVLimiter(limiter workqueue.RateLimiter) func(*ProvisionController) error

CreateProvisionedPVLimiter is the configuration of rate limiter for queue of unsaved PersistentVolumes. If set, PVs that fail to be saved to Kubernetes API server will be re-enqueued to a separate workqueue with this limiter and re-tried until they are saved to API server. There is no limit of retries. The main difference to other CreateProvisionedPV* option is that the storage asset is never deleted and the controller continues saving PV to API server indefinitely. This option cannot be used with CreateProvisionedPVBackoff or CreateProvisionedPVInterval or CreateProvisionedPVRetryCount.

func CreateProvisionedPVRetryCount

func CreateProvisionedPVRetryCount(createProvisionedPVRetryCount int) func(*ProvisionController) error

CreateProvisionedPVRetryCount is the number of retries when we create a PV object for a provisioned volume. Defaults to 5. If PV is not saved after given number of retries, corresponding storage asset (volume) is deleted! Only one of CreateProvisionedPVInterval+CreateProvisionedPVRetryCount or CreateProvisionedPVBackoff or CreateProvisionedPVLimiter can be used. Deprecated: Use CreateProvisionedPVLimiter instead, it tries indefinitely.

func DeletionTimeout

func DeletionTimeout(timeout time.Duration) func(*ProvisionController) error

DeletionTimeout sets the amount of time that deleting a volume may take. The default is unlimited.

func ExponentialBackOffOnError

func ExponentialBackOffOnError(exponentialBackOffOnError bool) func(*ProvisionController) error

ExponentialBackOffOnError determines whether to exponentially back off from failures of Provision and Delete. Defaults to true.

func FailedDeleteThreshold

func FailedDeleteThreshold(failedDeleteThreshold int) func(*ProvisionController) error

FailedDeleteThreshold is the threshold for max number of retries on failures of Delete. Set to 0 to retry indefinitely. Defaults to 15.

func FailedProvisionThreshold

func FailedProvisionThreshold(failedProvisionThreshold int) func(*ProvisionController) error

FailedProvisionThreshold is the threshold for max number of retries on failures of Provision. Set to 0 to retry indefinitely. Defaults to 15.

func LeaderElection

func LeaderElection(leaderElection bool) func(*ProvisionController) error

LeaderElection determines whether to enable leader election or not. Defaults to true.

func LeaderElectionNamespace

func LeaderElectionNamespace(leaderElectionNamespace string) func(*ProvisionController) error

LeaderElectionNamespace is the kubernetes namespace in which to create the leader election object. Defaults to the same namespace in which the the controller runs.

func LeaseDuration

func LeaseDuration(leaseDuration time.Duration) func(*ProvisionController) error

LeaseDuration is the duration that non-leader candidates will wait to force acquire leadership. This is measured against time of last observed ack. Defaults to 15 seconds.

func MetricsAddress

func MetricsAddress(metricsAddress string) func(*ProvisionController) error

MetricsAddress sets the ip address that metrics serve serves on.

func MetricsInstance

func MetricsInstance(m metrics.Metrics) func(*ProvisionController) error

MetricsInstance defines which metrics collection to update. Default: metrics.Metrics.

func MetricsPath

func MetricsPath(metricsPath string) func(*ProvisionController) error

MetricsPath sets the endpoint path of metrics server.

func MetricsPort

func MetricsPort(metricsPort int32) func(*ProvisionController) error

MetricsPort sets the port that metrics server serves on. Default: 0, set to non-zero to enable.

func NodesLister

func NodesLister(nodeLister corelistersv1.NodeLister) func(*ProvisionController) error

NodesLister sets the informer to use for accessing Nodes. This is needed only for PVCs which have a selected node. Defaults to using a GET instead of an informer.

Which approach is better depends on factors like cluster size and ratio of PVCs with a selected node.

func ProvisionTimeout

func ProvisionTimeout(timeout time.Duration) func(*ProvisionController) error

ProvisionTimeout sets the amount of time that provisioning a volume may take. The default is unlimited.

func RateLimiter

func RateLimiter(rateLimiter workqueue.RateLimiter) func(*ProvisionController) error

RateLimiter is the workqueue.RateLimiter to use for the provisioning and deleting work queues. If set, ExponentialBackOffOnError is ignored.

func RenewDeadline

func RenewDeadline(renewDeadline time.Duration) func(*ProvisionController) error

RenewDeadline is the duration that the acting master will retry refreshing leadership before giving up. Defaults to 10 seconds.

func ResyncPeriod

func ResyncPeriod(resyncPeriod time.Duration) func(*ProvisionController) error

ResyncPeriod is how often the controller relists PVCs, PVs, & storage classes. OnUpdate will be called even if nothing has changed, meaning failed operations may be retried on a PVC/PV every resyncPeriod regardless of whether it changed. Defaults to 15 minutes.

func RetryPeriod

func RetryPeriod(retryPeriod time.Duration) func(*ProvisionController) error

RetryPeriod is the duration the LeaderElector clients should wait between tries of actions. Defaults to 2 seconds.

func Threadiness

func Threadiness(threadiness int) func(*ProvisionController) error

Threadiness is the number of claim and volume workers each to launch. Defaults to 4.

func VolumesInformer

func VolumesInformer(informer cache.SharedInformer) func(*ProvisionController) error

VolumesInformer sets the informer to use for accessing PersistentVolumes. Defaults to using a internal informer.

Types

type BlockProvisioner

type BlockProvisioner interface {
	Provisioner
	// SupportsBlock returns whether provisioner supports block volume.
	SupportsBlock(context.Context) bool
}

BlockProvisioner is an optional interface implemented by provisioners to determine whether it supports block volume.

type DeletionGuard

type DeletionGuard interface {
	// ShouldDelete returns whether deleting the PV should be attempted.
	ShouldDelete(context.Context, *v1.PersistentVolume) bool
}

DeletionGuard is an optional interface implemented by provisioners to determine whether a PV should be deleted.

type IgnoredError

type IgnoredError struct {
	Reason string
}

IgnoredError is the value for Delete to return to indicate that the call has been ignored and no action taken. In case multiple provisioners are serving the same storage class, provisioners may ignore PVs they are not responsible for (e.g. ones they didn't create). The controller will act accordingly, i.e. it won't emit a misleading VolumeFailedDelete event.

func (*IgnoredError) Error

func (e *IgnoredError) Error() string

type ProvisionController

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

ProvisionController is a controller that provisions PersistentVolumes for PersistentVolumeClaims.

func NewProvisionController

func NewProvisionController(
	client kubernetes.Interface,
	provisionerName string,
	provisioner Provisioner,
	options ...func(*ProvisionController) error,
) *ProvisionController

NewProvisionController creates a new provision controller using the given configuration parameters and with private (non-shared) informers.

func (*ProvisionController) HasRun

func (ctrl *ProvisionController) HasRun() bool

HasRun returns whether the controller has Run

func (*ProvisionController) Run

func (ctrl *ProvisionController) Run(ctx context.Context)

Run starts all of this controller's control loops

type ProvisionOptions

type ProvisionOptions struct {
	// StorageClass is a reference to the storage class that is used for
	// provisioning for this volume
	StorageClass *storageapis.StorageClass

	// PV.Name of the appropriate PersistentVolume. Used to generate cloud
	// volume name.
	PVName string

	// PVC is reference to the claim that lead to provisioning of a new PV.
	// Provisioners *must* create a PV that would be matched by this PVC,
	// i.e. with required capacity, accessMode, labels matching PVC.Selector and
	// so on.
	PVC *v1.PersistentVolumeClaim

	// Node selected by the scheduler for the volume.
	SelectedNode *v1.Node
}

ProvisionOptions contains all information required to provision a volume

type Provisioner

type Provisioner interface {
	// Provision creates a volume i.e. the storage asset and returns a PV object
	// for the volume. The provisioner can return an error (e.g. timeout) and state
	// ProvisioningInBackground to tell the controller that provisioning may be in
	// progress after Provision() finishes. The controller will call Provision()
	// again with the same parameters, assuming that the provisioner continues
	// provisioning the volume. The provisioner must return either final error (with
	// ProvisioningFinished) or success eventually, otherwise the controller will try
	// forever (unless FailedProvisionThreshold is set).
	Provision(context.Context, ProvisionOptions) (*v1.PersistentVolume, ProvisioningState, error)
	// Delete removes the storage asset that was created by Provision backing the
	// given PV. Does not delete the PV object itself.
	//
	// May return IgnoredError to indicate that the call has been ignored and no
	// action taken.
	Delete(context.Context, *v1.PersistentVolume) error
}

Provisioner is an interface that creates templates for PersistentVolumes and can create the volume as a new resource in the infrastructure provider. It can also remove the volume it created from the underlying storage provider.

type ProvisioningState

type ProvisioningState string

ProvisioningState is state of volume provisioning. It tells the controller if provisioning could be in progress in the background after Provision() call returns or the provisioning is 100% finished (either with success or error).

const (
	// ProvisioningInBackground tells the controller that provisioning may be in
	// progress in background after Provision call finished.
	ProvisioningInBackground ProvisioningState = "Background"
	// ProvisioningFinished tells the controller that provisioning for sure does
	// not continue in background, error code of Provision() is final.
	ProvisioningFinished ProvisioningState = "Finished"
	// ProvisioningNoChange tells the controller that provisioning state is the same as
	// before the call - either ProvisioningInBackground or ProvisioningFinished from
	// the previous Provision(). This state is typically returned by a provisioner
	// before it could reach storage backend - the provisioner could not check status
	// of provisioning and previous state applies. If this state is returned from the
	// first Provision call, ProvisioningFinished is assumed (the provisioning
	// could not even start).
	ProvisioningNoChange ProvisioningState = "NoChange"
	// ProvisioningReschedule tells the controller that it shall stop all further
	// attempts to provision the volume and instead ask the Kubernetes scheduler
	// to pick a different node. This only makes sense for volumes with a selected
	// node, i.e. those with late binding, and must only be returned when it is certain
	// that provisioning does not continue in the background. The error returned together
	// with this state contains further information why rescheduling is needed.
	ProvisioningReschedule ProvisioningState = "Reschedule"
)

type Qualifier

type Qualifier interface {
	// ShouldProvision returns whether provisioning for the claim should
	// be attempted.
	ShouldProvision(context.Context, *v1.PersistentVolumeClaim) bool
}

Qualifier is an optional interface implemented by provisioners to determine whether a claim should be provisioned as early as possible (e.g. prior to leader election).

type VolumeStore

type VolumeStore interface {
	// StoreVolume makes sure a volume is saved to Kubernetes API server.
	// If no error is returned, caller can assume that PV was saved or
	// is being saved in background.
	// In error is returned, no PV was saved and corresponding PVC needs
	// to be re-queued (so whole provisioning needs to be done again).
	StoreVolume(claim *v1.PersistentVolumeClaim, volume *v1.PersistentVolume) error

	// Runs any background goroutines for implementation of the interface.
	Run(ctx context.Context, threadiness int)
}

VolumeStore is an interface that's used to save PersistentVolumes to API server. Implementation of the interface add custom error recovery policy. A volume is added via StoreVolume(). It's enough to store the volume only once. It is not possible to remove a volume, even when corresponding PVC is deleted and PV is not necessary any longer. PV will be always created. If corresponding PVC is deleted, the PV will be deleted by Kubernetes using standard deletion procedure. It saves us some code here.

func NewBackoffStore

func NewBackoffStore(client kubernetes.Interface,
	eventRecorder record.EventRecorder,
	backoff *wait.Backoff,
	ctrl *ProvisionController,
) VolumeStore

NewBackoffStore returns VolumeStore that uses blocking exponential backoff to save PVs.

func NewVolumeStoreQueue

func NewVolumeStoreQueue(
	client kubernetes.Interface,
	limiter workqueue.RateLimiter,
	claimsIndexer cache.Indexer,
	eventRecorder record.EventRecorder,
) VolumeStore

NewVolumeStoreQueue returns VolumeStore that uses asynchronous workqueue to save PVs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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