Skip to content

Commit

Permalink
pruning: Allow specification of FieldSelector
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justinsb committed Oct 7, 2021
1 parent 625ffdf commit 42b7f6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions channels/pkg/api/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions channels/pkg/channels/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 42b7f6f

Please sign in to comment.