From 0025c9e524647a2a42f37b369c3a1a64b5769450 Mon Sep 17 00:00:00 2001 From: Michal Gorniewski Date: Fri, 6 Jul 2018 16:34:26 +0200 Subject: [PATCH] fix(#1099): CustomResourceDefinitions: withResourceVersion() causes NoSuchMethodError --- CHANGELOG.md | 2 ++ .../CustomResourceOperationsImpl.java | 8 +++++ .../java/io/fabric8/kubernetes/TestUtils.java | 35 +++++++++++++++++++ .../fabric8/kubernetes/client/ConfigTest.java | 22 +++++------- .../client/internal/CertUtilsTest.java | 19 +++++----- 5 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 kubernetes-client/src/test/java/io/fabric8/kubernetes/TestUtils.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b64ff30341..21295a757a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ #### 4.0.4 (To be released) Bugs + * Fix #1099 : CustomResourceDefinitions: withResourceVersion() causes NoSuchMethodError + * Fix #1156 : Watcher does not have correct authentication information in Openshift environment. * Fix #1125 : ConfigMap labels are ignored when using mock KubernetesServer diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java index a9d57ff31c4..2ac62b49d23 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationsImpl.java @@ -21,11 +21,14 @@ import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition; import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; import io.fabric8.kubernetes.client.dsl.Gettable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; import io.fabric8.kubernetes.client.dsl.Replaceable; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.Watchable; import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; import io.fabric8.kubernetes.internal.KubernetesDeserializer; import okhttp3.OkHttpClient; @@ -105,4 +108,9 @@ public Resource load(InputStream is) { public Gettable fromServer() { return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getType(), getListType(), getDoneableType()); } + + @Override + public Watchable> withResourceVersion(String resourceVersion) { + return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getType(), getListType(), getDoneableType()); + } } diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/TestUtils.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/TestUtils.java new file mode 100644 index 00000000000..e922a954b3b --- /dev/null +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/TestUtils.java @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.kubernetes; + +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; + +public final class TestUtils { + + private TestUtils() { + } + + public static String filePath(URL path) { + try { + return Paths.get(path.toURI()).toString(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java index 814ede1bd5a..1778af7a99f 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java @@ -16,13 +16,17 @@ package io.fabric8.kubernetes.client; +import io.fabric8.kubernetes.TestUtils; import io.fabric8.kubernetes.client.utils.Serialization; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; import java.net.URLDecoder; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import okhttp3.OkHttpClient; @@ -41,10 +45,10 @@ public class ConfigTest { - private static final String TEST_KUBECONFIG_FILE = decodeUrl(ConfigTest.class.getResource("/test-kubeconfig").getFile()); - private static final String TEST_NAMESPACE_FILE = decodeUrl(ConfigTest.class.getResource("/test-namespace").getFile()); + private static final String TEST_KUBECONFIG_FILE = TestUtils.filePath(ConfigTest.class.getResource("/test-kubeconfig")); + private static final String TEST_NAMESPACE_FILE = TestUtils.filePath(ConfigTest.class.getResource("/test-namespace")); - private static final String TEST_CONFIG_YML_FILE = decodeUrl(ConfigTest.class.getResource("/test-config.yml").getFile()); + private static final String TEST_CONFIG_YML_FILE = TestUtils.filePath(ConfigTest.class.getResource("/test-config.yml")); @Before public void setUp() { @@ -197,14 +201,6 @@ public void testWithBuilderAndSystemProperties() { assertConfig(config); } - private static String decodeUrl(String url) { - try { - return URLDecoder.decode(url, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - @Test public void testMasterUrlWithServiceAccount() { System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, "/dev/null"); @@ -234,7 +230,7 @@ public void testWithKubeConfig() { assertEquals("https://172.28.128.4:8443/", config.getMasterUrl()); assertEquals("testns", config.getNamespace()); assertEquals("token", config.getOauthToken()); - assertTrue(config.getCaCertFile().endsWith("testns/ca.pem")); + assertTrue(config.getCaCertFile().endsWith("testns/ca.pem".replace("/", File.separator))); assertTrue(new File(config.getCaCertFile()).isAbsolute()); } @@ -247,7 +243,7 @@ public void testWithKubeConfigAndOverrideContext() { assertEquals("https://172.28.128.4:8443/", config.getMasterUrl()); assertEquals("production", config.getNamespace()); assertEquals("supertoken", config.getOauthToken()); - assertTrue(config.getCaCertFile().endsWith("testns/ca.pem")); + assertTrue(config.getCaCertFile().endsWith("testns/ca.pem".replace("/", File.separator))); assertTrue(new File(config.getCaCertFile()).isAbsolute()); } diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java index 31d2b3ec27f..41529fec800 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/internal/CertUtilsTest.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes.client.internal; +import io.fabric8.kubernetes.TestUtils; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient; @@ -22,7 +23,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.net.URL; import java.net.URLDecoder; +import java.nio.file.Paths; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -41,7 +45,7 @@ public class CertUtilsTest { - private static String FABRIC8_STORE_PATH = decodeUrl(CertUtilsTest.class.getResource("/ssl/fabric8-store").getPath()); + private static String FABRIC8_STORE_PATH = TestUtils.filePath(CertUtilsTest.class.getResource("/ssl/fabric8-store")); private static char[] FABRIC8_STORE_PASSPHRASE = "fabric8".toCharArray(); private Properties systemProperties; @@ -125,13 +129,13 @@ public void testLoadKeyStoreFromFileUsingConfigProperties() @Test public void testLoadKeyStoreFromFileUsingSystemProperties() - throws InvalidKeySpecException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { + throws InvalidKeySpecException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, URISyntaxException { System.setProperty(CertUtils.KEY_STORE_SYSTEM_PROPERTY, FABRIC8_STORE_PATH); System.setProperty(CertUtils.KEY_STORE_PASSWORD_SYSTEM_PROPERTY, String.valueOf(FABRIC8_STORE_PASSPHRASE)); - String privateKeyPath = decodeUrl(getClass().getResource("/ssl/fabric8").getPath()); - String multipleCertsPath = decodeUrl(getClass().getResource("/ssl/multiple-certs.pem").getPath()); + String privateKeyPath = TestUtils.filePath(getClass().getResource("/ssl/fabric8")); + String multipleCertsPath = TestUtils.filePath(getClass().getResource("/ssl/multiple-certs.pem")); KeyStore trustStore = CertUtils.createKeyStore(null, multipleCertsPath, null, privateKeyPath, "RSA", "changeit", null, null); @@ -156,11 +160,4 @@ private InputStream getMultipleCertsInputSteam() throws IOException { return CertUtils.getInputStreamFromDataOrFile(null, "src/test/resources/ssl/multiple-certs.pem"); } - private static String decodeUrl(String url) { - try { - return URLDecoder.decode(url, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } }