pruning: Allow specification of FieldSelector

FieldSelector allows for filtering by name (as well as a few other
attributes).  Though we aren't using this today, filtering by name is
something we've discussed as being valuable in future, and by putting
it in the API now we avoid version skew problems should we need to
introduce it in future.
This commit is contained in:
justinsb 2021-10-07 08:00:37 -04:00
parent 41d2779805
commit 0594eee373
2 changed files with 19 additions and 4 deletions

View File

@ -70,18 +70,32 @@ type AddonSpec struct {
Version string `json:"version,omitempty"`
// PruneSpec specifies how old objects should be removed (pruned).
Prune *PruneSpec `json:"prune,omitempty"`
}
// PruneSpec specifies how old objects should be removed (pruned).
type PruneSpec struct {
// Kinds specifies the objects to be pruned, by Kind.
Kinds []PruneKindSpec `json:"kinds,omitempty"`
}
// PruneKindSpec specifies pruning for a particular Kind of object.
type PruneKindSpec struct {
Group string `json:"group,omitempty"`
Kind string `json:"kind,omitempty"`
Namespaces []string `json:"namespaces,omitempty"`
LabelSelector string `json:"labelSelector,omitempty"`
// Group specifies the object Group to be pruned (required).
Group string `json:"group,omitempty"`
// Kind specifies the object Kind to be pruned (required).
Kind string `json:"kind,omitempty"`
// Namespaces limits pruning only to objects in certain namespaces.
Namespaces []string `json:"namespaces,omitempty"`
// LabelSelector limits pruning only to objects matching the specified labels.
LabelSelector string `json:"labelSelector,omitempty"`
// FieldSelector allows pruning only of objects matching the field selector.
// (This isn't currently used, but adding it now lets us start without worrying about version skew)
FieldSelector string `json:"fieldSelector,omitempty"`
}
func (a *Addons) Verify() error {

View File

@ -83,6 +83,7 @@ func (p *Pruner) pruneObjectsOfKind(ctx context.Context, gk schema.GroupKind, sp
var listOptions v1.ListOptions
listOptions.LabelSelector = spec.LabelSelector
listOptions.FieldSelector = spec.FieldSelector
baseResource := p.Client.Resource(gvr)
if len(spec.Namespaces) == 0 {