Skip to content

Conversation

@jaypipes
Copy link
Member

Adds a flexible label selector functionality to the gdt-kube plugin.

When selecting objects from the Kubernetes API, you can use a label selector in the kube.get and kube.delete test spec actions. This label selector functionality is incredibly flexible. You can use a kubectl-style label selector string, like so:

 - name: select pods that have the "app=argo" label but do NOT have the "app=argo-rollouts" or "app=argorollouts" label
   kube:
     get:
       type: pod
       labels: app in (argo),app notin (argo-rollouts,argorollouts)

The kube.get.labels field can also be a map of string to string, which is more aligned with how gdt's YAML syntax is structured. This example selects pods that have both the app=myapp and the region=myregion label:

 - name: select pods that have BOTH the app=myapp AND region=myregion label
   kube:
     get:
       type: pod
       labels:
         app: myapp
         region: myregion

The kube.get.labels-in field is a map of string to slice of strings and gets translated into a "label IN (val1, val2)" expression. This example selects pods that have either the app=myapp label or the app=test label:

 - name: select pods that have EITHER the app=myapp OR app=test label
   kube:
     get:
       type: pod
       labels-in:
         app:
          - myapp
          - test

The kube.get.labels-not-in field is also a map of string to slice of strings and gets translated into a label NOTIN (val1, val2) expression. This example selects pods that do not have either the app=myapp or the app=test label.

 - name: select pods that have DON'T HAVE the app=myapp OR app=test label
   kube:
     get:
       type: pod
       labels-not-in:
         app:
          - myapp
          - test

You can combine the kube.get.labels, kube.get.labels-in and kube.get.labels-not-in fields to create complex querying expressions. This example selects pods that have the app=myapp label and have either the category=test or category=staging label and do not have a personal=true label:

 - name: select pods that have have an app=myapp label AND have either a category=test or category=staging label AND do not have the personal=true label
   kube:
     get:
       type: pod
       labels:
         app: myapp
       labels-in:
         category:
          - test
          - staging
       labels-not-in:
         personal:
          - true

Issue #35

@jaypipes jaypipes requested a review from a-hilaly December 22, 2025 16:21
Adds a flexible label selector functionality to the `gdt-kube` plugin.

When selecting objects from the Kubernetes API, you can use a label selector in
the `kube.get` and `kube.delete` test spec actions. This label selector
functionality is incredibly flexible. You can use a `kubectl`-style label
selector string, like so:

```yaml
 - name: select pods that have the "app=argo" label but do NOT have the "app=argo-rollouts" or "app=argorollouts" label
   kube:
     get:
       type: pod
       labels: app in (argo),app notin (argo-rollouts,argorollouts)
```

The `kube.get.labels` field can also be a map of string to string, which is
more aligned with how `gdt`'s YAML syntax is structured. This example selects
pods that have **both** the `app=myapp` **and** the `region=myregion` label:

```yaml
 - name: select pods that have BOTH the app=myapp AND region=myregion label
   kube:
     get:
       type: pod
       labels:
         app: myapp
         region: myregion
```

The `kube.get.labels-in` field is a map of string to slice of strings and gets
translated into a "label IN (val1, val2)" expression. This example selects pods
that have **either** the `app=myapp` label **or** the `app=test` label:

```yaml
 - name: select pods that have EITHER the app=myapp OR app=test label
   kube:
     get:
       type: pod
       labels-in:
         app:
          - myapp
          - test
```

The `kube.get.labels-not-in` field is also a map of string to slice of strings
and gets translated into a `label NOTIN (val1, val2)` expression. This example
selects pods that **do not** have either the `app=myapp` or the `app=test`
label.

```yaml
 - name: select pods that have DON'T HAVE the app=myapp OR app=test label
   kube:
     get:
       type: pod
       labels-not-in:
         app:
          - myapp
          - test
```

You can combine the `kube.get.labels`, `kube.get.labels-in` and
`kube.get.labels-not-in` fields to create complex querying expressions. This
example selects pods that have the `app=myapp` label **and** have **either**
the `category=test` or `category=staging` label **and** do **not** have a
`personal=true` label:

```yaml
 - name: select pods that have have an app=myapp label AND have either a category=test or category=staging label AND do not have the personal=true label
   kube:
     get:
       type: pod
       labels:
         app: myapp
       labels-in:
         category:
          - test
          - staging
       labels-not-in:
         personal:
          - true
```

Issue gdt-dev#35

Signed-off-by: Jay Pipes <[email protected]>
@jaypipes jaypipes force-pushed the jaypipes/set-based-label-selectors branch from 038aa6b to de15fa6 Compare December 22, 2025 16:25
@jaypipes jaypipes merged commit 7ee1a6b into gdt-dev:main Dec 22, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant