From 0594eee373a8c9a7abb3c938b12fd608badcca87 Mon Sep 17 00:00:00 2001 From: justinsb Date: Thu, 7 Oct 2021 08:00:37 -0400 Subject: [PATCH] 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. --- channels/pkg/api/channel.go | 22 ++++++++++++++++++---- channels/pkg/channels/prune.go | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/channels/pkg/api/channel.go b/channels/pkg/api/channel.go index 97c0850815..61657f5ea8 100644 --- a/channels/pkg/api/channel.go +++ b/channels/pkg/api/channel.go @@ -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 { diff --git a/channels/pkg/channels/prune.go b/channels/pkg/channels/prune.go index 5e6bd404a3..33c35bb4d6 100644 --- a/channels/pkg/channels/prune.go +++ b/channels/pkg/channels/prune.go @@ -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 {