prune

package
v0.0.0-...-ed447de Latest Latest
Warning

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

Go to latest
Published: Sep 21, 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

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

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

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

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

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

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

Pruner is an object that runs a prune job.

func NewPruner

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

func (p Pruner) GVK() schema.GroupVersionKind

GVK returns the schema.GroupVersionKind that the Pruner has set

func (Pruner) Labels

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

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

func (Pruner) Namespace

func (p Pruner) Namespace() string

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

func (Pruner) Prune

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

Prune runs the pruner.

type PrunerOption

type PrunerOption func(p *Pruner)

PrunerOption configures the pruner.

func WithLabels

func WithLabels(labels map[string]string) PrunerOption

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

func WithNamespace

func WithNamespace(namespace string) PrunerOption

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

type Registry

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

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

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry is a default Registry configuration

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new Registry

func (*Registry) IsPrunable

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

IsPrunable checks if an object is prunable

func (*Registry) RegisterIsPrunableFunc

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

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

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

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

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

func (*Unprunable) Error

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