Skip to content

Commit b97d36e

Browse files
authored
docs: add configuration section (#1545)
1 parent ae2724f commit b97d36e

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

docs/documentation/configuration.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Configuring JOSDK
3+
description: Configuration options
4+
layout: docs
5+
permalink: /docs/configuration
6+
---
7+
8+
# Configuration options
9+
10+
The Java Operator SDK (JOSDK for short) provides several abstractions that work great out of the
11+
box. However, while we strive to cover the most common cases with the default behavior, we also
12+
recognize that that default behavior is not always what any given user might want for their
13+
operator. Numerous configuration options are therefore provided to help people tailor the
14+
framework to their needs.
15+
16+
Configuration options act at several levels, depending on which behavior you wish to act upon:
17+
- `Operator`-level using `ConfigurationService`
18+
- `Reconciler`-level using `ControllerConfiguration`
19+
- `DependentResouce`-level using the `DependentResourceConfigurator` interface
20+
- `EventSource`-level: some event sources, such as `InformerEventSource`, might need to be
21+
fine-tuned to properly identify which events will trigger the associated reconciler.
22+
23+
## Operator-level configuration
24+
25+
Configuration that impacts the whole operator is performed via the `ConfigurationService` class.
26+
An instance is provided by the `ConfigurationServiceProvider.instance()` method. This is the
27+
normal way for user-code to retrieve the current `ConfigurationService` instance. Sensible
28+
defaults are provided but you can change the default behavior by overriding the current
29+
configuration using `ConfigurationServiceProvider.overrideCurrent` method, providing a
30+
`ConfigurationServiceOverrider` `Consumer` that will apply the modifications you wish to perform
31+
on the configuration.
32+
33+
For instance, if you wish to not validate that the CRDs are present on your cluster when the
34+
operator starts and configure leader election, you would do something similar to:
35+
36+
```java
37+
ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false)
38+
.withLeaderElectionConfiguration(new LeaderElectionConfiguration("bar", "barNS")));
39+
```
40+
41+
Note that you can also obtain the same result by passing the `ConfigurationServiceOverrider`
42+
`Consumer` instance to the `Operator` constructor:
43+
44+
```java
45+
new Operator(o -> o.checkingCRDAndValidateLocalModel(false)
46+
.withLeaderElectionConfiguration(new LeaderElectionConfiguration("bar","barNS")));
47+
```
48+
49+
## Reconciler-level configuration
50+
51+
While reconcilers are typically configured using the `@ControllerConfiguration` annotation, it
52+
is also possible to override the configuration at runtime, when the reconciler is registered
53+
with the operator instance, either by passing it a completely new `ControllerConfiguration`
54+
instance or by preferably overriding some aspects of the current configuration using a
55+
`ControllerConfigurationOverrider` `Consumer`:
56+
57+
```java
58+
Operator operator;
59+
Reconciler reconciler;
60+
...
61+
operator.register(reconciler, configOverrider ->
62+
configOverrider.withFinalizer("my-nifty-operator/finalizer").withLabelSelector("foo=bar"));
63+
```
64+
65+
## DependentResource-level configuration
66+
67+
`DependentResource` implementations can implement the `DependentResourceConfigurator` interface
68+
to pass information to the implementation. For example, the SDK
69+
provides specific support for the `KubernetesDependentResource`, which can be configured via the
70+
`@KubernetesDependent` annotation. This annotation is, in turn, converted into a
71+
`KubernetesDependentResourceConfig` instance, which is then passed to the `configureWith` method
72+
implementation.
73+
74+
TODO: still subject to change / uniformization
75+
76+
## EventSource-level configuration
77+
78+
TODO

0 commit comments

Comments
 (0)