From b026f2c07ed815f14e62df4d4e2289a61f96c37c Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Tue, 6 Aug 2019 19:28:56 +0100 Subject: [PATCH] Bump fabric8 kubernetes-client from 4.1.3 to 4.5.2 * Bump sundrio.version from 0.16.4 to 0.17.2 * Remove KubernetesDeserializer thread safety workaround. * Simplify code used to turn off HTTP/2, utilizing new method in KC 4.4.0 * Remove generic parameter from KubernetesResource (relates to https://github.com/fabric8io/kubernetes-client/issues/1661) --- address-space-controller/pom.xml | 6 - api-model/pom.xml | 1 + .../io/enmasse/common/model/AbstractList.java | 2 +- .../internal/KubernetesDeserializer.java | 156 ------------------ api-server/pom.xml | 6 - pom.xml | 4 +- service-broker/pom.xml | 6 - standard-controller/pom.xml | 8 - .../enmasse/systemtest/platform/Minikube.java | 14 +- .../systemtest/platform/OpenShift.java | 11 +- 10 files changed, 10 insertions(+), 204 deletions(-) delete mode 100644 api-model/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java diff --git a/address-space-controller/pom.xml b/address-space-controller/pom.xml index de0528a6e2f..706b4d36045 100644 --- a/address-space-controller/pom.xml +++ b/address-space-controller/pom.xml @@ -142,12 +142,6 @@ META-INF/*.RSA - - io.fabric8:kubernetes-model - - io/fabric8/kubernetes/internal/KubernetesDeserializer** - - diff --git a/api-model/pom.xml b/api-model/pom.xml index a9e31938c8f..aa485f2d568 100644 --- a/api-model/pom.xml +++ b/api-model/pom.xml @@ -49,6 +49,7 @@ org.slf4j slf4j-api + test ch.qos.logback diff --git a/api-model/src/main/java/io/enmasse/common/model/AbstractList.java b/api-model/src/main/java/io/enmasse/common/model/AbstractList.java index 8dd9a3e6c3b..acaf42926fc 100644 --- a/api-model/src/main/java/io/enmasse/common/model/AbstractList.java +++ b/api-model/src/main/java/io/enmasse/common/model/AbstractList.java @@ -18,7 +18,7 @@ @SuppressWarnings("serial") public abstract class AbstractList extends AbstractResource - implements KubernetesResource, KubernetesResourceList { + implements KubernetesResource, KubernetesResourceList { @Valid private ListMeta metadata = new ListMeta(); diff --git a/api-model/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java b/api-model/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java deleted file mode 100644 index 1b7bbba54a4..00000000000 --- a/api-model/src/main/java/io/fabric8/kubernetes/internal/KubernetesDeserializer.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - - -package io.fabric8.kubernetes.internal; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import io.fabric8.kubernetes.api.model.KubernetesResource; -import io.fabric8.kubernetes.api.KubernetesResourceMappingProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesDeserializer extends JsonDeserializer { - - private static final Logger log = LoggerFactory.getLogger(KubernetesDeserializer.class); - - - private static final String KIND = "kind"; - private static final String API_VERSION = "apiVersion"; - private static final String KEY_SEPARATOR = "#"; - - private static final Map> MAP = new ConcurrentHashMap<>(); - private static final List PACKAGES; - - static { - log.warn("Using EnMasse specific KubernetesDeserializer with threadsafe map - see https://github.com/fabric8io/kubernetes-client/issues/1634"); - - //Use service loader to load extension types. - for (KubernetesResourceMappingProvider provider : ServiceLoader.load(KubernetesResourceMappingProvider.class)) { - for (Map.Entry> entry : provider.getMappings().entrySet()) { - String key = entry.getKey(); - Class value = entry.getValue(); - //If the model is shaded (which is as part of kubernetes-client uberjar) this is going to cause conflicts. - //This is why we NEED TO filter out incompatible resources. - if (KubernetesResource.class.isAssignableFrom(value)) { - MAP.put(key, value); - } - } - } - - PACKAGES = new ArrayList(){{ - add("io.fabric8.kubernetes.api.model."); - add("io.fabric8.kubernetes.api.model.apiextensions."); - add("io.fabric8.kubernetes.api.model.apps."); - add("io.fabric8.kubernetes.api.model.authentication."); - add("io.fabric8.kubernetes.api.model.authorization."); - add("io.fabric8.kubernetes.api.model.batch."); - add("io.fabric8.kubernetes.api.model.extensions."); - add("io.fabric8.kubernetes.api.model.networking."); - add("io.fabric8.kubernetes.api.model.policy."); - add("io.fabric8.kubernetes.api.model.rbac."); - add("io.fabric8.kubernetes.api.model.storage."); - add("io.fabric8.openshift.api.model."); - }}; - } - - @Override - public KubernetesResource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { - ObjectNode node = jp.readValueAsTree(); - String key = getKey(node); - if (key != null) { - Class resourceType = getTypeForKey(key); - if (resourceType == null) { - throw ctxt.mappingException("No resource type found for:" + key); - } else { - return jp.getCodec().treeToValue(node, resourceType); - } - } - return null; - } - - /** - * Return a string representation of the key of the type: #. - */ - private static final String getKey(ObjectNode node) { - JsonNode apiVersion = node.get(API_VERSION); - JsonNode kind = node.get(KIND); - - return getKey(apiVersion != null ? apiVersion.textValue() : null, - kind != null ? kind.textValue() : null); - } - - /** - * Returns a composite key for apiVersion and kind. - */ - private static final String getKey(String apiVersion, String kind) { - if (kind == null) { - return null; - } else if (apiVersion == null) { - return kind; - } else { - return String.format("%s#%s", apiVersion, kind); - } - } - - /** - * Registers a Custom Resource Definition Kind - */ - public static void registerCustomKind(String kind, Class clazz) { - registerCustomKind(null, kind, clazz); - } - - /** - * Registers a Custom Resource Definition Kind - */ - public static void registerCustomKind(String apiVersion, String kind, Class clazz) { - MAP.put(getKey(apiVersion, kind), clazz); - } - - static Class getTypeForKey(String key) { - Class result = MAP.get(key); - if (result == null) { - String name = key != null && key.contains(KEY_SEPARATOR) ? - key.substring(key.indexOf(KEY_SEPARATOR) + 1) : - key; - - result = getInternalTypeForName(name); - } - - if (result != null) { - MAP.put(key, result); - } - return result; - } - - private static Class getInternalTypeForName(String name) { - - for (int i = 0; i < PACKAGES.size(); i++ ) { - Class result = loadClassIfExists(PACKAGES.get(i) + name); - if (result != null) { - return result; - } - } - - return null; - } - - private static Class loadClassIfExists(String className) { - try { - return KubernetesDeserializer.class.getClassLoader().loadClass(className); - } catch (Throwable t) { - return null; - } - } -} diff --git a/api-server/pom.xml b/api-server/pom.xml index fe980b0847e..76f05b204bb 100644 --- a/api-server/pom.xml +++ b/api-server/pom.xml @@ -142,12 +142,6 @@ META-INF/*.RSA - - io.fabric8:kubernetes-model - - io/fabric8/kubernetes/internal/KubernetesDeserializer** - - diff --git a/pom.xml b/pom.xml index 4d0a12f3dfd..d72ebf7b488 100644 --- a/pom.xml +++ b/pom.xml @@ -42,8 +42,8 @@ 11 1.9.0 - 4.1.3 - 0.16.4 + 4.5.2 + 0.17.2 3.7.1 1.7.21 1.2.3 diff --git a/service-broker/pom.xml b/service-broker/pom.xml index 07a96687f5e..6ad72cc73e1 100644 --- a/service-broker/pom.xml +++ b/service-broker/pom.xml @@ -148,12 +148,6 @@ META-INF/*.RSA - - io.fabric8:kubernetes-model - - io/fabric8/kubernetes/internal/KubernetesDeserializer** - - diff --git a/standard-controller/pom.xml b/standard-controller/pom.xml index 01811424455..045c582ef5d 100644 --- a/standard-controller/pom.xml +++ b/standard-controller/pom.xml @@ -110,14 +110,6 @@ io.enmasse.controller.standard.StandardController - - - io.fabric8:kubernetes-model - - io/fabric8/kubernetes/internal/KubernetesDeserializer** - - - diff --git a/systemtests/src/main/java/io/enmasse/systemtest/platform/Minikube.java b/systemtests/src/main/java/io/enmasse/systemtest/platform/Minikube.java index 39eae891f28..6bc7d8565aa 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/platform/Minikube.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/platform/Minikube.java @@ -10,26 +10,20 @@ import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.utils.HttpClientUtils; -import okhttp3.OkHttpClient; -import okhttp3.Protocol; import org.slf4j.Logger; import java.util.Arrays; -import java.util.Collections; public class Minikube extends Kubernetes { private static Logger log = CustomLogger.getLogger(); protected Minikube(String globalNamespace) { super(globalNamespace, () -> { - Config config = new ConfigBuilder().build(); + Config config = new ConfigBuilder() + .withHttp2Disable(true) // Workaround https://github.com/square/okhttp/issues/3146 + .build(); - OkHttpClient httpClient = HttpClientUtils.createHttpClient(config); - // Workaround https://github.com/square/okhttp/issues/3146 - httpClient = httpClient.newBuilder().protocols(Collections.singletonList(Protocol.HTTP_1_1)).build(); - - return new DefaultKubernetesClient(httpClient, config); + return new DefaultKubernetesClient(config); }); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/platform/OpenShift.java b/systemtests/src/main/java/io/enmasse/systemtest/platform/OpenShift.java index 2aef89b1465..9b7bd3cdba6 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/platform/OpenShift.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/platform/OpenShift.java @@ -10,17 +10,12 @@ import io.enmasse.systemtest.utils.TestUtils; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; -import io.fabric8.kubernetes.client.utils.HttpClientUtils; import io.fabric8.openshift.api.model.Route; import io.fabric8.openshift.client.DefaultOpenShiftClient; import io.fabric8.openshift.client.OpenShiftClient; import io.fabric8.openshift.client.OpenShiftConfig; -import okhttp3.OkHttpClient; -import okhttp3.Protocol; import org.slf4j.Logger; -import java.util.Collections; - /** * Handles interaction with openshift cluster */ @@ -34,12 +29,10 @@ public OpenShift(Environment environment, String globalNamespace) { super(globalNamespace, () -> { Config config = new ConfigBuilder().withMasterUrl(environment.getApiUrl()) .withOauthToken(environment.getApiToken()) + .withHttp2Disable(true) // // Workaround https://github.com/square/okhttp/issues/3146 .build(); - OkHttpClient httpClient = HttpClientUtils.createHttpClient(config); - // Workaround https://github.com/square/okhttp/issues/3146 - httpClient = httpClient.newBuilder().protocols(Collections.singletonList(Protocol.HTTP_1_1)).build(); - return new DefaultOpenShiftClient(httpClient, new OpenShiftConfig(config)); + return new DefaultOpenShiftClient(new OpenShiftConfig(config)); }); }