Selectors

Selectors allow you to include or exclude resource objects when returned or reconciled by Jikkou.

Overview

Selectors filter which resources Jikkou operates on. They are passed via the --selector (or -s) CLI option and can be used with any command that accepts resources, including get, apply, create, update, delete, diff, validate, and prepare.

You can specify multiple selectors by repeating the --selector flag, and control how they are combined using the --selector-match option.

Selector Expression Syntax

A selector expression follows one of two formats:

  • With an explicit selector type prefix:
<SELECTOR_TYPE>: <EXPRESSION>
  • Using the default field selector (the prefix can be omitted):
<KEY> <OPERATOR> <VALUE>
<KEY> <OPERATOR> (VALUE1, VALUE2, ...)

Supported Selectors

Field (default)

The field selector filters resources based on any field in the resource object, using dot-notation to navigate nested properties.

field: <KEY> <OPERATOR> <VALUE>
field: <KEY> <OPERATOR> (VALUE1, VALUE2, ...)

Since field is the default selector type, the field: prefix can be omitted.

Examples

# Select resources by name
jikkou get kafkatopics -s 'metadata.name IN (my-topic, other-topic)'

# Select by kind
jikkou get kafkatopics -s 'kind IN (KafkaTopic)'

# Select by label (using field selector)
jikkou get kafkatopics -s 'metadata.labels.environment IN (staging, production)'

# Select topics matching a regex pattern
jikkou get kafkatopics -s 'metadata.name MATCHES (^public-.*)'

# Exclude internal topics
jikkou get kafkatopics -s 'metadata.name DOESNOTMATCH (^__.*)'

# With explicit field: prefix (equivalent to above)
jikkou get kafkatopics -s 'field: metadata.name MATCHES (^public-.*)'

Label

The label selector provides a shorthand to filter resources by their metadata labels, without needing the full metadata.labels. path prefix.

label: <LABEL_KEY> <OPERATOR> <VALUE>
label: <LABEL_KEY> <OPERATOR> (VALUE1, VALUE2, ...)

Examples

# Select resources with a specific label value
jikkou get kafkatopics -s 'label: environment IN (staging, production)'

# Select resources that have a specific label (regardless of value)
jikkou get kafkatopics -s 'label: team EXISTS'

# Select resources that do NOT have a specific label
jikkou get kafkatopics -s 'label: deprecated DOESNOTEXIST'

Expression (since Jikkou v0.36)

The expr selector enables complex filtering using the Common Expression Language (CEL). This is the most powerful selector type, supporting conditions on nested fields, arrays, maps, and computed expressions.

The resource being evaluated is available as the resource variable.

expr: <CEL_EXPRESSION>

Examples

# Select resources with a label value in a list
jikkou get kafkatopics \
  -s 'expr: has(resource.metadata.labels.env) && resource.metadata.labels.env in ["staging", "production"]'

# Select Kafka topics with at least 12 partitions
jikkou get kafkatopics \
  -s 'expr: resource.kind == "KafkaTopic" && resource.spec.partitions >= 12'

# Select resources missing a specific annotation
jikkou get kafkatopics \
  -s 'expr: !has(resource.metadata.annotations["mycompany.io/owner"])'

Expression Operators

The following operators are available for field and label selectors:

OperatorDescription
INMatch if the value is in the given list
NOTINMatch if the value is not in the given list
EXISTSMatch if the field or label exists
DOESNOTEXISTMatch if the field or label does not exist
MATCHESMatch if the value matches a regular expression
DOESNOTMATCHMatch if the value does not match the regular expression

Matching Strategies

When specifying multiple selectors, use --selector-match to control how they are combined:

StrategyBehavior
ALLThe resource must match all selectors (logical AND).
ANYThe resource must match at least one selector (logical OR).
NONEThe resource must match none of the selectors (logical NOT).

The default strategy is ALL.

Examples

# Match resources whose name starts with "__" OR is exactly "_schemas" (ANY)
jikkou get kafkatopics \
  --selector 'metadata.name MATCHES (^__.*)' \
  --selector 'metadata.name IN (_schemas)' \
  --selector-match ANY

# Match resources that have both labels (ALL - default)
jikkou get kafkatopics \
  -s 'label: environment IN (production)' \
  -s 'label: team EXISTS'

# Exclude resources matching any selector (NONE)
jikkou get kafkatopics \
  -s 'metadata.name MATCHES (^__.*)' \
  -s 'metadata.name IN (_schemas)' \
  --selector-match NONE

SEE ALSO