From 90bd021c5149d9b7a3b2fb5237d0ca1543b8ecc7 Mon Sep 17 00:00:00 2001 From: avanish23 Date: Wed, 23 Oct 2024 20:14:16 +0530 Subject: [PATCH 1/2] allow pod filtering using labels and annotations --- .../pkg/resource/dataselect/propertyname.go | 2 ++ .../resource/dataselect/stdcomparabletypes.go | 18 ++++++++++++++++++ modules/api/pkg/resource/pod/common.go | 4 ++++ modules/web/src/common/resources/list.ts | 9 ++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/api/pkg/resource/dataselect/propertyname.go b/modules/api/pkg/resource/dataselect/propertyname.go index c3c0e83eb40f..c034a7d4b87d 100644 --- a/modules/api/pkg/resource/dataselect/propertyname.go +++ b/modules/api/pkg/resource/dataselect/propertyname.go @@ -28,4 +28,6 @@ const ( FirstSeenProperty = "firstSeen" LastSeenProperty = "lastSeen" ReasonProperty = "reason" + LabelProperty = "label" + AnnotationsProperty = "annotations" ) diff --git a/modules/api/pkg/resource/dataselect/stdcomparabletypes.go b/modules/api/pkg/resource/dataselect/stdcomparabletypes.go index 322bd4bc6799..5f4f754701b6 100644 --- a/modules/api/pkg/resource/dataselect/stdcomparabletypes.go +++ b/modules/api/pkg/resource/dataselect/stdcomparabletypes.go @@ -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 +} diff --git a/modules/api/pkg/resource/pod/common.go b/modules/api/pkg/resource/pod/common.go index bbfbc01142cf..65baf18f25bc 100644 --- a/modules/api/pkg/resource/pod/common.go +++ b/modules/api/pkg/resource/pod/common.go @@ -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 diff --git a/modules/web/src/common/resources/list.ts b/modules/web/src/common/resources/list.ts index 0c42947cada8..8589a880106a 100644 --- a/modules/web/src/common/resources/list.ts +++ b/modules/web/src/common/resources/list.ts @@ -276,7 +276,14 @@ export abstract class ResourceListBase 1 && filters.length % 2 == 0 + ? this.cardFilter_.query + : ''; + if (filterByQuery) { return result.set('filterBy', filterByQuery); } From c3756451c9cdd52703e5b93fbc5bc2d8a2efda53 Mon Sep 17 00:00:00 2001 From: avanish23 Date: Fri, 1 Nov 2024 20:36:13 +0530 Subject: [PATCH 2/2] added more workloads for filtering --- modules/api/pkg/resource/cronjob/common.go | 4 ++++ modules/api/pkg/resource/daemonset/common.go | 4 ++++ modules/api/pkg/resource/deployment/common.go | 4 ++++ modules/api/pkg/resource/job/common.go | 4 ++++ modules/api/pkg/resource/replicaset/common.go | 4 ++++ modules/api/pkg/resource/serviceaccount/common.go | 2 ++ modules/api/pkg/resource/statefulset/common.go | 4 ++++ 7 files changed, 26 insertions(+) diff --git a/modules/api/pkg/resource/cronjob/common.go b/modules/api/pkg/resource/cronjob/common.go index b695eaed9613..3e8abe1298d1 100644 --- a/modules/api/pkg/resource/cronjob/common.go +++ b/modules/api/pkg/resource/cronjob/common.go @@ -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 diff --git a/modules/api/pkg/resource/daemonset/common.go b/modules/api/pkg/resource/daemonset/common.go index a423b2ec3c41..2a5a7dc4e122 100644 --- a/modules/api/pkg/resource/daemonset/common.go +++ b/modules/api/pkg/resource/daemonset/common.go @@ -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 diff --git a/modules/api/pkg/resource/deployment/common.go b/modules/api/pkg/resource/deployment/common.go index 6d4393dd2e0c..4878f6cbfeed 100644 --- a/modules/api/pkg/resource/deployment/common.go +++ b/modules/api/pkg/resource/deployment/common.go @@ -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 diff --git a/modules/api/pkg/resource/job/common.go b/modules/api/pkg/resource/job/common.go index fc1a192bb4e6..4b35a623efa2 100644 --- a/modules/api/pkg/resource/job/common.go +++ b/modules/api/pkg/resource/job/common.go @@ -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 diff --git a/modules/api/pkg/resource/replicaset/common.go b/modules/api/pkg/resource/replicaset/common.go index 709893fbbcb1..59cf98db85c1 100644 --- a/modules/api/pkg/resource/replicaset/common.go +++ b/modules/api/pkg/resource/replicaset/common.go @@ -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 diff --git a/modules/api/pkg/resource/serviceaccount/common.go b/modules/api/pkg/resource/serviceaccount/common.go index 9870b52b6dda..bb40a520d82e 100644 --- a/modules/api/pkg/resource/serviceaccount/common.go +++ b/modules/api/pkg/resource/serviceaccount/common.go @@ -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 diff --git a/modules/api/pkg/resource/statefulset/common.go b/modules/api/pkg/resource/statefulset/common.go index 1a7f0ba80e89..f2e04e7e6f31 100644 --- a/modules/api/pkg/resource/statefulset/common.go +++ b/modules/api/pkg/resource/statefulset/common.go @@ -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