Skip to content

Commit

Permalink
Merge pull request #189 from replicatedhq/gerard/sc-114293/pod-list-f…
Browse files Browse the repository at this point in the history
…ilter

bug: kubectl describe node does not apply node filter on pod list
  • Loading branch information
diamonwiggins authored Oct 18, 2024
2 parents 1d4f417 + b29c32a commit 29040ff
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 29040ff

Please sign in to comment.