prune

package
Version: v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultJobIsPrunable added in v0.11.0

func DefaultJobIsPrunable(obj client.Object) error

DefaultJobIsPrunable is a default IsPrunableFunc to be used specifically with Job resources. It marks a Job resource as prunable if it's Status.CompletionTime value is not `nil`, indicating that the Job has completed This can be overridden by registering your own IsPrunableFunc via the RegisterIsPrunableFunc method

func DefaultPodIsPrunable added in v0.11.0

func DefaultPodIsPrunable(obj client.Object) error

DefaultPodIsPrunable is a default IsPrunableFunc to be used specifically with Pod resources. It marks a Pod resource as prunable if it's Status.Phase is "Succeeded" This can be overridden by registering your own IsPrunableFunc via the RegisterIsPrunableFunc method

func IsUnprunable added in v0.11.0

func IsUnprunable(target error) bool

IsUnprunable checks if a given error is that of Unprunable. Returns true if the given error is of type Unprunable, and false if it is not

func RegisterIsPrunableFunc added in v0.11.0

func RegisterIsPrunableFunc(gvk schema.GroupVersionKind, isPrunable IsPrunableFunc)

RegisterIsPrunableFunc registers a function to check whether it is safe to prune a resource of a certain type.

Types

type IsPrunableFunc added in v0.11.0

type IsPrunableFunc func(obj client.Object) error

IsPrunableFunc is a function that checks the data of an object to see whether or not it is safe to prune it. It should return `nil` if it is safe to prune, `Unprunable` if it is unsafe, or another error. It should safely assert the object is the expected type, otherwise it might panic.

type Pruner added in v0.11.0

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

Pruner is an object that runs a prune job.

func NewPruner added in v0.11.0

func NewPruner(prunerClient client.Client, gvk schema.GroupVersionKind, strategy StrategyFunc, opts ...PrunerOption) (*Pruner, error)

NewPruner returns a pruner that uses the given strategy to prune objects that have the given GVK

func (Pruner) GVK added in v0.11.0

func (p Pruner) GVK() schema.GroupVersionKind

GVK returns the schema.GroupVersionKind that the Pruner has set

func (Pruner) Labels added in v0.11.0

func (p Pruner) Labels() map[string]string

Labels returns the labels that the Pruner is using to find resources to prune

func (Pruner) Namespace added in v0.11.0

func (p Pruner) Namespace() string

Namespace returns the namespace that the Pruner is using to find resources to prune

func (Pruner) Prune added in v0.11.0

func (p Pruner) Prune(ctx context.Context) ([]client.Object, error)

Prune runs the pruner.

type PrunerOption added in v0.11.0

type PrunerOption func(p *Pruner)

PrunerOption configures the pruner.

func WithLabels added in v0.11.0

func WithLabels(labels map[string]string) PrunerOption

WithLabels can be used to set the Labels field when configuring a Pruner

func WithNamespace added in v0.11.0

func WithNamespace(namespace string) PrunerOption

WithNamespace can be used to set the Namespace field when configuring a Pruner

type Registry added in v0.11.0

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

Registry is used to register a mapping of GroupVersionKind to an IsPrunableFunc

func DefaultRegistry added in v0.11.0

func DefaultRegistry() *Registry

DefaultRegistry is a default Registry configuration

func NewRegistry added in v0.11.0

func NewRegistry() *Registry

NewRegistry creates a new Registry

func (*Registry) IsPrunable added in v0.11.0

func (r *Registry) IsPrunable(obj client.Object) error

IsPrunable checks if an object is prunable

func (*Registry) RegisterIsPrunableFunc added in v0.11.0

func (r *Registry) RegisterIsPrunableFunc(gvk schema.GroupVersionKind, isPrunable IsPrunableFunc)

RegisterIsPrunableFunc registers a function to check whether it is safe to prune a resource of a certain type.

type StrategyFunc

type StrategyFunc func(ctx context.Context, objs []client.Object) ([]client.Object, error)

StrategyFunc takes a list of resources and returns the subset to prune.

func NewPruneByCountStrategy added in v0.11.0

func NewPruneByCountStrategy(count int) StrategyFunc

NewPruneByCountStrategy returns a StrategyFunc that will return a list of resources to prune based on a maximum count of resources allowed. If the max count of resources is exceeded, the oldest resources are prioritized for pruning

func NewPruneByDateStrategy added in v0.11.0

func NewPruneByDateStrategy(date time.Time) StrategyFunc

NewPruneByDateStrategy returns a StrategyFunc that will return a list of resources to prune where the resource CreationTimestamp is after the given time.Time.

type Unprunable added in v0.11.0

type Unprunable struct {
	Obj    *client.Object
	Reason string
}

Unprunable indicates that it is not allowed to prune a specific object.

func (*Unprunable) Error added in v0.11.0

func (e *Unprunable) Error() string

Error returns a string representation of an `Unprunable` error.

Jump to

Keyboard shortcuts

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