Skip to content

feat: Add ability to filter by resource labels and annotations #9572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/cronjob/common.go
Original file line number Diff line number Diff line change
@@ -35,6 +35,10 @@ func (self CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.Com
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/daemonset/common.go
Original file line number Diff line number Diff line change
@@ -75,6 +75,10 @@ func (self DaemonSetCell) GetProperty(name dataselect.PropertyName) dataselect.C
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
2 changes: 2 additions & 0 deletions modules/api/pkg/resource/dataselect/propertyname.go
Original file line number Diff line number Diff line change
@@ -28,4 +28,6 @@ const (
FirstSeenProperty = "firstSeen"
LastSeenProperty = "lastSeen"
ReasonProperty = "reason"
LabelProperty = "label"
AnnotationsProperty = "annotations"
)
18 changes: 18 additions & 0 deletions modules/api/pkg/resource/dataselect/stdcomparabletypes.go
Original file line number Diff line number Diff line change
@@ -97,3 +97,21 @@ func ints64Compare(a, b int64) int {
}
return -1
}

type StdComparableMap map[string]string

func (self StdComparableMap) Compare(otherV ComparableValue) int {
return 0
}

func (self StdComparableMap) Contains(otherV ComparableValue) bool {
other := otherV.(StdComparableString)
keyValueList := strings.Split(string(other), "=")
if len(keyValueList) != 2 {
return false
}
if value, ok := self[keyValueList[0]]; ok {
return value == keyValueList[1]
}
return false
}
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/deployment/common.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@ func (self DeploymentCell) GetProperty(name dataselect.PropertyName) dataselect.
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/job/common.go
Original file line number Diff line number Diff line change
@@ -36,6 +36,10 @@ func (self JobCell) GetProperty(name dataselect.PropertyName) dataselect.Compara
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/pod/common.go
Original file line number Diff line number Diff line change
@@ -191,6 +191,10 @@ func (self PodCell) GetProperty(name dataselect.PropertyName) dataselect.Compara
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/replicaset/common.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ func (self ReplicaSetCell) GetProperty(name dataselect.PropertyName) dataselect.
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
2 changes: 2 additions & 0 deletions modules/api/pkg/resource/serviceaccount/common.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ func (self ServiceAccountCell) GetProperty(name dataselect.PropertyName) datasel
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// If name is not supported then just return a constant dummy value, sort will have no effect.
return nil
4 changes: 4 additions & 0 deletions modules/api/pkg/resource/statefulset/common.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ func (self StatefulSetCell) GetProperty(name dataselect.PropertyName) dataselect
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselect.NamespaceProperty:
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
case dataselect.LabelProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Labels)
case dataselect.AnnotationsProperty:
return dataselect.StdComparableMap(self.ObjectMeta.Annotations)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
9 changes: 8 additions & 1 deletion modules/web/src/common/resources/list.ts
Original file line number Diff line number Diff line change
@@ -276,7 +276,14 @@ export abstract class ResourceListBase<T extends ResourceList, R extends Resourc
result = params;
}

const filterByQuery = this.cardFilter_.query ? `name,${this.cardFilter_.query}` : '';
const filters = this.cardFilter_.query ? this.cardFilter_.query.split(',') : [];

const filterByQuery = filters.length == 1
? `name,${this.cardFilter_.query}`
: filters.length > 1 && filters.length % 2 == 0
? this.cardFilter_.query
: '';

if (filterByQuery) {
return result.set('filterBy', filterByQuery);
}