Search code examples
gokubernetesterratest

how to filter pods against multiple label selectors with terratest?


I have a code that uses k8s module of terratest to list pods based on label selector.

pods, err := k8s.ListPodsE(
    t,
    k8soptions,
    filter,
)

where the filter is initialized with a string labelSelector like this,

filter := metav1.ListOptions{
        LabelSelector: "kubeslice.io/app=foo",
}

So if I want to filter pods against more than one labels, say pods which has bothkubeslice.io/pod-type=gateway & kubeslice.io/app=foo, how can I achieve that in this method ?


Solution

  • As pointed out by doublethink and I tested, we could provide a comma separated string of label selectors like this.

    filter := metav1.ListOptions{
            LabelSelector: "kubeslice.io/app=foo,kubeslice.io/app=bar",
    }