Configuring informers

Reconcilers are notified of changes happening on the cluster by informers, which watch resources of a given type and cache them locally. The Java Operator SDK (JOSDK) lets you configure these informers with the @Informer annotation (io.javaoperatorsdk.operator.api.config.informer.Informer), which can be used in two places:

  • as the informer field of @ControllerConfiguration, to configure the informer watching the primary resources of a reconciler

  • as the informer field of @KubernetesDependent, to configure the informer watching the secondary resources managed by a dependent resource

@ControllerConfiguration(name = "exposedapp", informer = @Informer(
        namespaces = Constants.WATCH_CURRENT_NAMESPACE,
        labelSelector = "app.kubernetes.io/managed-by=exposedapp"))
public class ExposedAppReconciler implements Reconciler<ExposedApp> {
    // ...
}
@KubernetesDependent(informer = @Informer(labelSelector = "app.kubernetes.io/managed-by=exposedapp"))
public class DeploymentDependent extends CRUDKubernetesDependentResource<Deployment, ExposedApp> {
    // ...
}

QOSDK processes the informer configuration of your reconcilers at build time. Some of the parameters can also be overridden using configuration properties, as detailed in Overriding the informer configuration with properties.

@Informer parameters

Parameter Default Description

name

none

Name of the informer. Mostly useful to identify the informer, for example in logs or health checks.

namespaces

see description

Namespaces the informer watches. You can provide a list of namespace names or use one of the constants defined in io.javaoperatorsdk.operator.api.reconciler.Constants:

  • WATCH_ALL_NAMESPACES: watch all the namespaces of the cluster

  • WATCH_CURRENT_NAMESPACE: only watch the namespace the operator is deployed in

  • SAME_AS_CONTROLLER: watch the same namespaces as the associated controller (only makes sense for secondary resources)

If no namespace is specified, a controller’s informer watches all namespaces, while a secondary resource’s informer watches the same namespaces as its controller.

labelSelector

none

Label selector that resources must match to be watched by the informer. Several comma-separated requirements can be specified, in which case resources must match all of them.

shardSelector

none

Label selector used to restrict the informer to a single shard, typically when the same workload is split across several operator instances. It uses the same syntax as labelSelector. When both are set, only the resources matching both selectors are watched.

fieldSelector

none

Field selector that resources must match to be watched by the informer, specified as an array of @Field annotations:

@Informer(fieldSelector = @Field(path = "type", value = "kubernetes.io/tls"))

Set negated = true on a @Field to select resources for which the field has a different value. QOSDK validates the field names at build time: besides metadata.name and metadata.namespace, only the fields supported by Kubernetes for the watched resource type are accepted (for custom resources, the selectable fields declared in the CRD).

onAddFilter, onUpdateFilter, onDeleteFilter, genericFilter

none

Classes implementing OnAddFilter, OnUpdateFilter, OnDeleteFilter and GenericFilter respectively, used to discard events before they trigger a reconciliation. genericFilter applies to all event types. See the JOSDK documentation on event filters for more details.

followControllerNamespaceChanges

true

Whether the informer should follow the changes when the namespaces watched by the controller are changed at runtime.

itemStore

none

ItemStore implementation to use instead of the default cache of the informer, for example to bound the cache size. See the JOSDK documentation on bounded caches for more details.

informerListLimit

none

Maximum number of items returned by a single list call when the informer starts. If set, the initial load of the informer cache is paginated.

comparableResourceVersions

true

Whether resource versions can be considered as integers and therefore compared with each other.

withoutNamespaceIndex

false

Whether to remove the namespace index that the informer maintains by default.

JOSDK never reads that index, so removing it saves one entry per cached resource. It is worth setting when the informer caches a large number of resources and nothing looks them up by namespace, in particular in combination with a custom itemStore that only keeps a reduced form of each resource.

Event sources that disagree on this setting cannot share an informer, since the index cannot be present for one of them and absent for the other.

ghostResourceCacheCheckInterval

Deprecated and not used anymore: ghost resource checking is now triggered by the informer itself.

The filter and item store classes configured on a @ControllerConfiguration are instantiated by QOSDK at build time. They therefore need to provide a public no-arg constructor.

Overriding the informer configuration with properties

The following parameters of a controller’s informer can be overridden without changing the code, using the name of the reconciler (as configured with @ControllerConfiguration(name = …​)) to identify it:

Parameter Configuration property

namespaces

quarkus.operator-sdk.controllers."<name>".namespaces for a given controller or quarkus.operator-sdk.namespaces for all the controllers that do not explicitly set their namespaces

labelSelector

quarkus.operator-sdk.controllers."<name>".selector

shardSelector

quarkus.operator-sdk.controllers."<name>".shard-selector

fieldSelector

quarkus.operator-sdk.controllers."<name>".field-selectors, as a comma-separated list of <field>=<value> or <field>!=<value> expressions

For example:

quarkus.operator-sdk.controllers."exposedapp".namespaces=team-a,team-b
quarkus.operator-sdk.controllers."exposedapp".selector=app.kubernetes.io/managed-by=exposedapp
quarkus.operator-sdk.controllers."exposedapp".field-selectors=metadata.name!=ignored

These properties are runtime properties: when they are set, they take precedence over the values provided by the annotation. The operator-level quarkus.operator-sdk.namespaces property is only applied to the controllers for which namespaces are set neither with the annotation nor with a controller-specific property.

See the configuration reference for more details on these properties.