From 80eb617e7bc3cce0a68b3e7f7b958fd574819d78 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Thu, 2 Mar 2023 18:31:09 +0100 Subject: [PATCH] feat: make it possible to change the httpclient implementation Also document how to use a different implementation instead of the okhttp one which is the default one and currently, the one we recommend to use. Vert.X implementation is also coming along nicely. JDK implementation should work if you're using Java 17 and up, and will work with 11 when some bug fixes land in 11. --- caffeine-bounded-cache-support/pom.xml | 5 +++++ docs/documentation/v4-3-migration.md | 28 ++++++++++++++++++------ operator-framework-core/pom.xml | 6 +++++ operator-framework/pom.xml | 5 ++++- pom.xml | 24 +++++++++++++++++++- sample-operators/tomcat-operator/pom.xml | 10 +++++++++ 6 files changed, 69 insertions(+), 9 deletions(-) diff --git a/caffeine-bounded-cache-support/pom.xml b/caffeine-bounded-cache-support/pom.xml index 23b5334287..7b5223c339 100644 --- a/caffeine-bounded-cache-support/pom.xml +++ b/caffeine-bounded-cache-support/pom.xml @@ -54,6 +54,11 @@ test-jar test + + io.fabric8 + kubernetes-httpclient-okhttp + test + diff --git a/docs/documentation/v4-3-migration.md b/docs/documentation/v4-3-migration.md index f5022fa856..17d3be70b4 100644 --- a/docs/documentation/v4-3-migration.md +++ b/docs/documentation/v4-3-migration.md @@ -9,16 +9,16 @@ permalink: /docs/v4-3-migration ## Condition API Change -In Workflows the target of the condition was the managed resource itself, not the target dependent resource. +In Workflows the target of the condition was the managed resource itself, not the target dependent resource. This changed, now the API contains the dependent resource. New API: ```java public interface Condition { - - boolean isMet(DependentResource dependentResource, P primary, Context

context); - + + boolean isMet(DependentResource dependentResource, P primary, Context

context); + } ``` @@ -27,10 +27,24 @@ Former API: ```java public interface Condition { - boolean isMet(P primary, R secondary, Context

context); - + boolean isMet(P primary, R secondary, Context

context); + } ``` -Migration is trivial. Since the secondary resource can be accessed from the dependent resource. So to access the secondary +Migration is trivial. Since the secondary resource can be accessed from the dependent resource. So to access the +secondary resource just use `dependentResource.getSecondaryResource(primary,context)`. + +## HTTP client choice + +It is now possible to change the HTTP client used by the Fabric8 client to communicate with the Kubernetes API server. +By default, the SDK uses the historical default HTTP client which relies on Okhttp and there shouldn't be anything +needed to keep using this implementation. The `tomcat-operator` sample has been migrated to use the Vert.X based +implementation. You can see how to change the client by looking at +that [sample POM file](https://github.com/java-operator-sdk/java-operator-sdk/blob/d259fcd084f7e22032dfd0df3c7e64fe68850c1b/sample-operators/tomcat-operator/pom.xml#L37-L50): + +- You need to exclude the default implementation (in this case okhttp) from the `operator-framework` dependency +- You need to add the appropriate implementation dependency, `kubernetes-httpclient-vertx` in this case, HTTP client + implementations provided as part of the Fabric8 client all following the `kubernetes-httpclient-` + pattern for their artifact identifier. \ No newline at end of file diff --git a/operator-framework-core/pom.xml b/operator-framework-core/pom.xml index 7c6e42da69..4d09220023 100644 --- a/operator-framework-core/pom.xml +++ b/operator-framework-core/pom.xml @@ -68,6 +68,12 @@ io.fabric8 kubernetes-client + + + io.fabric8 + kubernetes-httpclient-okhttp + + org.slf4j diff --git a/operator-framework/pom.xml b/operator-framework/pom.xml index 8911516d8d..bb9e19b9ed 100644 --- a/operator-framework/pom.xml +++ b/operator-framework/pom.xml @@ -17,7 +17,10 @@ io.javaoperatorsdk operator-framework-core - + + io.fabric8 + kubernetes-httpclient-okhttp + org.apache.commons commons-lang3 diff --git a/pom.xml b/pom.xml index b3fc536ac4..cc5e8c28e2 100644 --- a/pom.xml +++ b/pom.xml @@ -110,7 +110,7 @@ io.fabric8 - kubernetes-client + kubernetes-client-api ${fabric8-client.version} @@ -200,6 +200,28 @@ caffeine ${caffeine.version} + + + io.fabric8 + kubernetes-httpclient-okhttp + ${fabric8-client.version} + + + io.fabric8 + kubernetes-httpclient-vertx + ${fabric8-client.version} + + + + + + + + + + + + diff --git a/sample-operators/tomcat-operator/pom.xml b/sample-operators/tomcat-operator/pom.xml index 6a38e2d93b..9ce4dd8e1b 100644 --- a/sample-operators/tomcat-operator/pom.xml +++ b/sample-operators/tomcat-operator/pom.xml @@ -37,6 +37,16 @@ io.javaoperatorsdk operator-framework + + + io.fabric8 + kubernetes-httpclient-okhttp + + + + + io.fabric8 + kubernetes-httpclient-vertx io.fabric8