Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
httpclient-tests:
strategy:
matrix:
httpclient: [ 'vertx', 'jdk', 'jetty' ]
httpclient: [ 'vertx-5', 'jdk', 'jetty' ]
uses: ./.github/workflows/integration-tests.yml
with:
java-version: 25
Expand Down
43 changes: 43 additions & 0 deletions docs/content/en/docs/migration/v5-7-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Migrating from v5.6 to v5.7
description: Migrating from v5.6 to v5.7
---

## Fabric8 Kubernetes Client upgraded to v8.0.0

v5.7 uses version 8.0.0 of the
[Fabric8 Kubernetes Client](https://github.com/fabric8io/kubernetes-client). Please consult the
client's own release notes and migration guide for the complete list of changes. The ones that are
most likely to affect operators built with JOSDK are described below.

### Jackson 3

The client moved from Jackson 2 to Jackson 3. The packages changed from `com.fasterxml.jackson` to
`tools.jackson` (the annotations from `jackson-annotations` are the exception and remain in
`com.fasterxml.jackson.annotation`). If your operator uses Jackson types directly, for example
`JsonNode` obtained from the client's `KubernetesSerialization`, update the imports and the
dependencies accordingly:

```java
// before
import com.fasterxml.jackson.databind.JsonNode;

// after
import tools.jackson.databind.JsonNode;
```

Other notable Jackson 3 differences:

- `JsonProcessingException` was replaced by `JacksonException`, which is unchecked.
- `JsonNode.fields()` was replaced by `properties()`, `fieldNames()` by `propertyNames()` and
`asText()` by `asString()`.
- `ObjectMapper` instances are created using builders, for example `YAMLMapper.builder().build()`.

### Ambiguous `withShardSelector(null)`

`Filterable` now has an additional `withShardSelector(ShardSelector)` overload next to
`withShardSelector(String)`. Calls passing a bare `null` no longer compile, cast the argument:

```java
client.pods().withShardSelector((String) null);
```
7 changes: 6 additions & 1 deletion operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@
<exclusions>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-okhttp</artifactId>
<artifactId>kubernetes-httpclient-vertx-5</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-${fabric8-httpclient-impl.name}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ public <R extends HasMetadata> R clone(R object) {
* you do not need to worry about setting the namespace information in most cases).
*
* <p>Previous versions of this class provided direct access to the serialization mechanism (via
* {@link com.fasterxml.jackson.databind.ObjectMapper}) or the client's configuration. This was
* somewhat confusing, in particular with respect to changes made in the Fabric8 client
* serialization architecture made in 6.7. The proper way to configure these aspects is now to
* configure the Kubernetes client accordingly and the SDK will extract the information it needs
* from this instance. The recommended way to do so is to create your operator with {@link
* {@link tools.jackson.databind.ObjectMapper}) or the client's configuration. This was somewhat
* confusing, in particular with respect to changes made in the Fabric8 client serialization
* architecture made in 6.7. The proper way to configure these aspects is now to configure the
* Kubernetes client accordingly and the SDK will extract the information it needs from this
* instance. The recommended way to do so is to create your operator with {@link
* io.javaoperatorsdk.operator.Operator#Operator(Consumer)}, passing your custom instance with
* {@link ConfigurationServiceOverrider#withKubernetesClient(KubernetesClient)}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.dependent.Matcher;

import com.fasterxml.jackson.databind.JsonNode;
import tools.jackson.databind.JsonNode;

public class GenericKubernetesResourceMatcher<R extends HasMetadata, P extends HasMetadata> {

Expand Down Expand Up @@ -262,7 +262,7 @@ private static boolean match(boolean equality, JsonNode diff, final List<String>
if (!ignoreList.isEmpty()) {
return nodeIsChildOf(diff, ignoreList);
}
return ADD.equals(diff.get(OP).asText());
return ADD.equals(diff.get(OP).asString());
}

static boolean nodeIsChildOf(JsonNode n, List<String> prefixes) {
Expand All @@ -276,6 +276,6 @@ static boolean nodeIsChildOf(JsonNode n, List<String> prefixes) {
}

static String getPath(JsonNode n) {
return n.get(PATH).asText();
return n.get(PATH).asString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.matcher.Matcher;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.node.NullNode;
import tools.jackson.databind.node.ObjectNode;

/** Shared helpers for the client-side patch based {@link Matcher} implementations. */
final class MatcherUtils {
Expand Down Expand Up @@ -66,9 +66,7 @@ private static JsonNode applyMergePatch(JsonNode target, JsonNode patch) {
}
var targetObject =
target.isObject() ? (ObjectNode) target : JsonNodeFactory.instance.objectNode();
var fields = patch.fields();
while (fields.hasNext()) {
var entry = fields.next();
for (var entry : patch.properties()) {
if (entry.getValue().isNull()) {
targetObject.remove(entry.getKey());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void stubInformerStore() {
.resources(Deployment.class)
.inNamespace("ns1")
.withLabelSelector((String) null)
.withShardSelector(null)
.withShardSelector((String) null)
.runnableInformer(0);
when(informer.getStore()).thenReturn(mock(Cache.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void setup() {
.resources(Deployment.class)
.inNamespace(NAMESPACE)
.withLabelSelector((String) null)
.withShardSelector(null)
.withShardSelector((String) null)
.runnableInformer(0);
when(informer.getStore()).thenReturn(mock(Cache.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void stubInformerStore() {
.resources(Deployment.class)
.inNamespace("ns1")
.withLabelSelector((String) null)
.withShardSelector(null)
.withShardSelector((String) null)
.runnableInformer(0);
when(informer.getStore()).thenReturn(mock(Cache.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

import io.javaoperatorsdk.operator.config.loader.ConfigProvider;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.dataformat.yaml.YAMLMapper;

/**
* A {@link ConfigProvider} that resolves configuration values from a YAML file.
Expand All @@ -44,7 +46,7 @@ public class YamlConfigProvider implements ConfigProvider {

private static final Logger log = LoggerFactory.getLogger(YamlConfigProvider.class);

private static final ObjectMapper MAPPER = new ObjectMapper(new YAMLFactory());
private static final ObjectMapper MAPPER = YAMLMapper.builder().build();

private final Map<String, Object> data;

Expand Down Expand Up @@ -101,7 +103,7 @@ private static Map<String, Object> load(Path path) {
}

try (InputStream in = Files.newInputStream(path);
com.fasterxml.jackson.core.JsonParser parser = MAPPER.getFactory().createParser(in)) {
JsonParser parser = MAPPER.createParser(in)) {
if (parser.nextToken() == null) {
log.debug(
"YAML file contains no mappings (possibly empty or comments only). "
Expand All @@ -113,6 +115,8 @@ private static Map<String, Object> load(Path path) {
return result != null ? result : Map.of();
} catch (IOException e) {
throw new UncheckedIOException("Failed to load config YAML from " + path, e);
} catch (JacksonException e) {
throw new UncheckedIOException("Failed to load config YAML from " + path, new IOException(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.javaoperatorsdk.operator.api.config.InformerStoppedHandler;
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;

import com.fasterxml.jackson.core.JsonProcessingException;
import tools.jackson.core.JacksonException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void onStop(SharedIndexInformer informer, Throwable ex) {
final var object = unmarshal.get("object");
resourceCreateAsVersion =
acceptOnlyIfUnsetOrEqualToAlreadySet(
resourceCreateAsVersion, object.get("apiVersion").asText());
resourceCreateAsVersion, object.get("apiVersion").asString());
// extract the asked resource version
failedResourceVersion =
acceptOnlyIfUnsetOrEqualToAlreadySet(
Expand All @@ -103,8 +103,8 @@ public void onStop(SharedIndexInformer informer, Throwable ex) {
.get("managedFields")
.get(0)
.get("apiVersion")
.asText());
} catch (JsonProcessingException e) {
.asString());
} catch (JacksonException e) {
throw new RuntimeException(e);
}
});
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<fabric8-httpclient-impl.name>jdk</fabric8-httpclient-impl.name>
<junit.version>6.1.3</junit.version>
<fabric8-client.version>7.9.0</fabric8-client.version>
<fabric8-client.version>8.0.0</fabric8-client.version>
<slf4j.version>2.0.18</slf4j.version>
<log4j.version>2.26.1</log4j.version>
<mokito.version>5.23.0</mokito.version>
Expand Down Expand Up @@ -236,6 +236,11 @@
<artifactId>kubernetes-httpclient-vertx</artifactId>
<version>${fabric8-client.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-vertx-5</artifactId>
<version>${fabric8-client.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-jdk</artifactId>
Expand Down
Loading