Skip to content

Commit

Permalink
add filter for pod list
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao committed Oct 17, 2024
1 parent 1d4f417 commit b29c32a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,15 @@ func filterObjectsByFields(object runtime.Object, selector fields.Selector) runt
}
}
return filtered
case *corev1.PodList:
filtered := &corev1.PodList{}
for _, item := range o.Items {
item := item
if selector.Matches(podToSelectableFields(&item)) {
filtered.Items = append(filtered.Items, *item.DeepCopy())
}
}
return filtered
default:
// TODO: do more
}
Expand Down Expand Up @@ -1496,6 +1505,16 @@ func eventToSelectableFields(event *corev1.Event) fields.Set {
return generic.MergeFieldsSets(specificFieldsSet, objectMetaFieldsSet)
}

// podToSelectableFields extracts fields from a Pod object to be used for selection or filtering
func podToSelectableFields(pod *corev1.Pod) fields.Set {
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&pod.ObjectMeta, true)
specificFieldsSet := fields.Set{
"spec.nodeName": pod.Spec.NodeName,
"status.phase": string(pod.Status.Phase),
}
return generic.MergeFieldsSets(specificFieldsSet, objectMetaFieldsSet)
}

func toTable(object runtime.Object, r *http.Request) (runtime.Object, error) {
switch o := object.(type) {
case *corev1.PodList:
Expand Down

0 comments on commit b29c32a

Please sign in to comment.