Skip to content

Commit

Permalink
fix(fabric8io#1099): CustomResourceDefinitions: withResourceVersion()…
Browse files Browse the repository at this point in the history
… causes NoSuchMethodError
  • Loading branch information
Michal Gorniewski committed Jul 31, 2018
1 parent 79d38b1 commit 0025c9e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,4 +108,9 @@ public Resource<T, D> load(InputStream is) {
public Gettable<T> fromServer() {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getType(), getListType(), getDoneableType());
}

@Override
public Watchable<Watch, Watcher<T>> withResourceVersion(String resourceVersion) {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
*/
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;
import io.fabric8.kubernetes.client.utils.Utils;
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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}

0 comments on commit 0025c9e

Please sign in to comment.