nsdelete

package
v1.2.16 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 17 Imported by: 0

README

Namespace Delete Controller

The Namespace Delete Controller is responsible for removing namespaces from the StorageOS cluster when the namespace has been removed from Kubernetes.

When a StorageOS-provisioned PVC is created in a Kubernetes namespace, if the namespace does not already exist in the StorageOS cluster then it is created and the StorageOS volume is created within it.

The opposite is not true - the StorageOS control plane does not remove namespaces after the last volume has been removed from it, as it can't tell whether a new volume will be provisioned to it. This can lead to multiple empty namespaces remaining in the cluster, unless they are deleted manually using the UI or CLI.

If the Kubernetes namespace is deleted, then we can safely assume that the namespace is no longer needed, and that it will be re-created if a new PVC is provisioned to it. Only empty namespaces will be deleted.

Trigger

The controller reconcile will trigger on any Kubernetes Namespace delete event.

Reconcile

When a Kubernetes namespace is deleted, a request is made to the StorageOS API to remove the namespace. The StorageOS API will only allow the delete to succeed if the namespace is empty and does not contain any volumes.

If the delete request failed, it will be requeued and retried after a backoff period.

If the namespace was not found, either because it was already deleted or it never had a PVC provisioned by StorageOS, the delete request will be considered successful.

Garbage Collection

In case a namespace delete event was missed during a restart or outage, a garbage collection runs periodically. It compares the list of namespaces known to StorageOS, and removes any that are no longer known to Kubernetes.

Garbage collection is run every hour by default (configurable via the -namespace-delete-gc-interval flag). It can be disabled by setting -namespace-delete-gc-interval to 0s.

Garbage collection is run on startup after a delay defined by the -namespace-delete-gc-delay flag.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller implements the SyncReconciler contoller interface, deleting namespaces in StorageOS when they have been detected as deleted in Kubernetes.

func NewController

func NewController(api NamespaceDeleter, log logr.Logger) (*Controller, error)

NewController returns a Controller that implements namespace garbage collection in StorageOS.

func (Controller) Delete

func (c Controller) Delete(ctx context.Context, obj client.Object) error

Delete receives a k8s object that's been deleted and calls the StorageOS api to remove it from management.

func (Controller) Ensure

func (c Controller) Ensure(ctx context.Context, obj client.Object) error

Ensure is a no-op. We only care about deletes.

func (Controller) List

List returns a list of namespaces known to StorageOS, as NamespacedNames. This is used for garbage collection and can be expensive. The garbage collector is run in a separate goroutine periodically, not affecting the main reconciliation control-loop.

type NamespaceDeleter

type NamespaceDeleter interface {
	DeleteNamespace(ctx context.Context, key client.ObjectKey) error
	ListNamespaces(ctx context.Context) ([]storageos.Object, error)
}

NamespaceDeleter provides access to removing namespaces from StorageOS.

type Predicate

type Predicate struct {
	predicate.IgnoreFuncs
}

Predicate filters events before enqueuing the keys. Ignore all but Delete events.

func (Predicate) Delete

func (p Predicate) Delete(e event.DeleteEvent) bool

Delete determines whether an object delete should trigger a reconcile.

type Reconciler

type Reconciler struct {
	client.Client

	objectv1.Reconciler
	// contains filtered or unexported fields
}

Reconciler reconciles a Namespace object by deleting the StorageOS namespace when the corresponding Kubernetes namespace is deleted.

func NewReconciler

func NewReconciler(api NamespaceDeleter, k8s client.Client, gcDelay time.Duration, gcInterval time.Duration) *Reconciler

NewReconciler returns a new Namespace delete reconciler.

The gcInterval determines how often the periodic resync operation should be run.

func (*Reconciler) SetupWithManager

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, workers int) error

SetupWithManager registers the controller with the controller manager.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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