Skip to content

Commit

Permalink
Merge pull request #89 from kubescape/add-field-selector-to-list-pods
Browse files Browse the repository at this point in the history
Added field selector to ListPods
  • Loading branch information
dwertent committed Jan 11, 2024
2 parents dacccc0 + e6d8909 commit 2d339e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion k8sinterface/k8sstatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ func SetLabel(labels map[string]string, key string, val bool) {
labels[key] = boolutils.BoolToString(val)
}

func (k8sAPI *KubernetesApi) ListPods(namespace string, podLabels map[string]string) (*corev1.PodList, error) {
func (k8sAPI *KubernetesApi) ListPods(namespace string, podLabels map[string]string, fieldSelector string) (*corev1.PodList, error) {
listOptions := metav1.ListOptions{}
if len(podLabels) > 0 {
set := labels.Set(podLabels)
listOptions.LabelSelector = set.AsSelector().String()
}

if fieldSelector != "" {
listOptions.FieldSelector = fieldSelector
}

pods, err := k8sAPI.KubernetesClient.CoreV1().Pods(namespace).List(context.Background(), listOptions)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2d339e8

Please sign in to comment.