Skip to content

Commit 74378cb

Browse files
csvirimetacosm
andcommitted
docs: migration to 4.4 (#1950)
Co-authored-by: Chris Laprun <[email protected]>
1 parent aca4dc1 commit 74378cb

File tree

5 files changed

+164
-9
lines changed

5 files changed

+164
-9
lines changed

Diff for: docs/_data/sidebar.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
url: /docs/glossary
1010
- title: Features
1111
url: /docs/features
12-
- title: Dependent Resource Feature
12+
- title: Dependent Resources
1313
url: /docs/dependent-resources
1414
- title: Workflows
1515
url: /docs/workflows
@@ -26,4 +26,8 @@
2626
- title: Migrating from v2 to v3
2727
url: /docs/v3-migration
2828
- title: Migrating from v3 to v3.1
29-
url: /docs/v3-1-migration
29+
url: /docs/v3-1-migration
30+
- title: Migrating from v4.2 to v4.3
31+
url: /docs/v4-3-migration
32+
- title: Migrating from v4.3 to v4.4
33+
url: /docs/v4-4-migration

Diff for: docs/documentation/v4-4-migration.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Migrating from v4.3 to v4.4
3+
description: Migrating from v4.3 to v4.4
4+
layout: docs
5+
permalink: /docs/v4-4-migration
6+
---
7+
8+
# Migrating from v4.3 to v4.4
9+
10+
## API changes
11+
12+
### ConfigurationService
13+
14+
We have simplified how to deal with the Kubernetes client. Previous versions provided direct
15+
access to underlying aspects of the client's configuration or serialization mechanism. However,
16+
the link between these aspects wasn't as explicit as it should have been. Moreover, the Fabric8
17+
client framework has also revised their serialization architecture in the 6.7 version (see [this
18+
fabric8 pull request](https://github.com/fabric8io/kubernetes-client/pull/4662) for a discussion of
19+
that change), moving from statically configured serialization to a per-client configuration
20+
(though it's still possible to share serialization mechanism between client instances). As a
21+
consequence, we made the following changes to the `ConfigurationService` API:
22+
23+
- Replaced `getClientConfiguration` and `getObjectMapper` methods by a new `getKubernetesClient`
24+
method: instead of providing the configuration and mapper, you now provide a client instance
25+
configured according to your needs and the SDK will extract the needed information from it
26+
27+
If you had previously configured a custom configuration or `ObjectMapper`, it is now recommended
28+
that you do so when creating your client instance, as follows, usually using
29+
`ConfigurationServiceOverrider.withKubernetesClient`:
30+
31+
```java
32+
33+
class Example {
34+
35+
public static void main(String[] args) {
36+
Config config; // your configuration
37+
ObjectMapper mapper; // your mapper
38+
final var operator = new Operator(overrider -> overrider.withKubernetesClient(
39+
new KubernetesClientBuilder()
40+
.withConfig(config)
41+
.withKubernetesSerialization(new KubernetesSerialization(mapper, true))
42+
.build()
43+
));
44+
}
45+
}
46+
```
47+
48+
Consequently, it is now recommended to get the client instance from the `ConfigurationService`.
49+
50+
### Operator
51+
52+
It is now recommended to configure your Operator instance by using a
53+
`ConfigurationServiceOverrider` when creating it. This allows you to change the default
54+
configuration values as needed. In particular, instead of passing a Kubernetes client instance
55+
explicitly to the Operator constructor, it is now recommended to provide that value using
56+
`ConfigurationServiceOverrider.withKubernetesClient` as shown above.
57+
58+
## Using Server-Side Apply in Dependent Resources
59+
60+
From this version by
61+
default [Dependent Resources](https://javaoperatorsdk.io/docs/dependent-resources) use
62+
[Server Side Apply (SSA)](https://kubernetes.io/docs/reference/using-api/server-side-apply/) to
63+
create and
64+
update Kubernetes resources. A
65+
new [default matching](https://github.com/java-operator-sdk/java-operator-sdk/blob/e95f9c8a8b8a8561c9a735e60fc5d82b7758df8e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java#L163-L163)
66+
algorithm is provided for `KubernetesDependentResource` that is based on `managedFields` of SSA. For
67+
details
68+
see [SSABasedGenericKubernetesResourceMatcher](https://github.com/java-operator-sdk/java-operator-sdk/blob/e95f9c8a8b8a8561c9a735e60fc5d82b7758df8e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/SSABasedGenericKubernetesResourceMatcher.java)
69+
70+
Since those features are hard to completely test, we provided feature flags to revert to the
71+
legacy behavior if needed,
72+
see those
73+
in [ConfigurationService](https://github.com/java-operator-sdk/java-operator-sdk/blob/e95f9c8a8b8a8561c9a735e60fc5d82b7758df8e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L268-L289)
74+
75+
Note that it is possible to override the related methods/behavior on class level when extending
76+
the `KubernetesDependentResource`.

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
6767
}
6868

6969
/**
70-
* Note that Operator by default closes the client on stop, this can be changed using
71-
* {@link ConfigurationService}
72-
*
7370
* @param client client to use to all Kubernetes related operations
7471
* @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
7572
* {@link ConfigurationService} values
7673
* @deprecated Use {@link Operator#Operator(Consumer)} instead, passing your custom client with
7774
* {@link ConfigurationServiceOverrider#withKubernetesClient(KubernetesClient)}
7875
*/
79-
@Deprecated
76+
@Deprecated(since = "4.4.0")
8077
public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
8178
this(initConfigurationService(client, overrider));
8279
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

+74-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ public interface ConfigurationService {
4242

4343

4444
/**
45-
* Used to clone custom resources. It is strongly suggested that implementors override this method
46-
* since the default implementation creates a new {@link Cloner} instance each time this method is
47-
* called.
45+
* Used to clone custom resources.
46+
*
47+
* <p>
48+
* <em>NOTE:</em> It is strongly suggested that implementors override this method since the
49+
* default implementation creates a new {@link Cloner} instance each time this method is called.
50+
* </p>
4851
*
4952
* @return the configured {@link Cloner}
5053
*/
@@ -57,6 +60,32 @@ public <R extends HasMetadata> R clone(R object) {
5760
};
5861
}
5962

63+
/**
64+
* Provides the fully configured {@link KubernetesClient} to use for controllers to the target
65+
* cluster. Note that this client only needs to be able to connect to the cluster, the SDK will
66+
* take care of creating the required connections to watch the target resources (in particular,
67+
* you do not need to worry about setting the namespace information in most cases).
68+
*
69+
* <p>
70+
* Previous versions of this class provided direct access to the serialization mechanism (via
71+
* {@link com.fasterxml.jackson.databind.ObjectMapper}) or the client's configuration. This was
72+
* somewhat confusing, in particular with respect to changes made in the Fabric8 client
73+
* serialization architecture made in 6.7. The proper way to configure these aspects is now to
74+
* configure the Kubernetes client accordingly and the SDK will extract the information it needs
75+
* from this instance. The recommended way to do so is to create your operator with
76+
* {@link io.javaoperatorsdk.operator.Operator#Operator(Consumer)}, passing your custom instance
77+
* with {@link ConfigurationServiceOverrider#withKubernetesClient(KubernetesClient)}.
78+
* </p>
79+
*
80+
* <p>
81+
* <em>NOTE:</em> It is strongly suggested that implementors override this method since the
82+
* default implementation creates a new {@link KubernetesClient} instance each time this method is
83+
* called.
84+
* </p>
85+
*
86+
* @return the configured {@link KubernetesClient}
87+
* @since 4.4.0
88+
*/
6089
default KubernetesClient getKubernetesClient() {
6190
return new KubernetesClientBuilder()
6291
.withConfig(new ConfigBuilder(Config.autoConfigure(null))
@@ -242,6 +271,25 @@ default ResourceClassResolver getResourceClassResolver() {
242271
return new DefaultResourceClassResolver();
243272
}
244273

274+
/**
275+
* Creates a new {@link ConfigurationService} instance used to configure an
276+
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
277+
* configuration and overriding specific aspects according to the provided
278+
* {@link ConfigurationServiceOverrider} instance.
279+
*
280+
* <p>
281+
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
282+
* your Operator instance as the configuration service is set at creation time and cannot be
283+
* subsequently changed. As a result, overriding values this way after the Operator has been
284+
* configured will not take effect.
285+
* </p>
286+
*
287+
* @param baseConfiguration the {@link ConfigurationService} to start from
288+
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
289+
* by the base configuration
290+
* @return a new {@link ConfigurationService} starting from the configuration provided as base but
291+
* with overridden values.
292+
*/
245293
static ConfigurationService newOverriddenConfigurationService(
246294
ConfigurationService baseConfiguration,
247295
Consumer<ConfigurationServiceOverrider> overrider) {
@@ -253,6 +301,25 @@ static ConfigurationService newOverriddenConfigurationService(
253301
return baseConfiguration;
254302
}
255303

304+
/**
305+
* Creates a new {@link ConfigurationService} instance used to configure an
306+
* {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
307+
* and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
308+
* instance.
309+
*
310+
* <p>
311+
* <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
312+
* your Operator instance as the configuration service is set at creation time and cannot be
313+
* subsequently changed. As a result, overriding values this way after the Operator has been
314+
* configured will not take effect.
315+
* </p>
316+
*
317+
* @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
318+
* by the default configuration
319+
* @return a new {@link ConfigurationService} overriding the default values with the ones provided
320+
* by the specified {@link ConfigurationServiceOverrider}
321+
* @since 4.4.0
322+
*/
256323
static ConfigurationService newOverriddenConfigurationService(
257324
Consumer<ConfigurationServiceOverrider> overrider) {
258325
return newOverriddenConfigurationService(new BaseConfigurationService(), overrider);
@@ -269,6 +336,8 @@ default ExecutorServiceManager getExecutorServiceManager() {
269336
* <a href="https://kubernetes.io/docs/reference/using-api/server-side-apply/">Server-Side
270337
* Apply</a> (SSA) by default. Note that the legacy approach, and this setting, might be removed
271338
* in the future.
339+
*
340+
* @since 4.4.0
272341
*/
273342
default boolean ssaBasedCreateUpdateForDependentResources() {
274343
return true;
@@ -280,6 +349,8 @@ default boolean ssaBasedCreateUpdateForDependentResources() {
280349
* Dependent Resources which is quite complex. As a consequence, we introduced this setting to
281350
* allow folks to revert to the previous matching algorithm if needed. Note, however, that the
282351
* legacy algorithm, and this setting, might be removed in the future.
352+
*
353+
* @since 4.4.0
283354
*/
284355
default boolean ssaBasedDefaultMatchingForDependentResources() {
285356
return true;

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public ConfigurationServiceOverrider withWorkflowExecutorService(
105105
return this;
106106
}
107107

108+
/**
109+
* Replaces the default {@link KubernetesClient} instance by the specified one. This is the
110+
* preferred mechanism to configure which client will be used to access the cluster.
111+
*
112+
* @param client the fully configured client to use for cluster access
113+
* @return this {@link ConfigurationServiceOverrider} for chained customization
114+
*/
108115
public ConfigurationServiceOverrider withKubernetesClient(KubernetesClient client) {
109116
this.client = client;
110117
return this;

0 commit comments

Comments
 (0)