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 54a6593
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
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
Expand Up @@ -22,7 +22,10 @@
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 +44,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 = filePath(ConfigTest.class.getResource("/test-kubeconfig"));
private static final String TEST_NAMESPACE_FILE = 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 = filePath(ConfigTest.class.getResource("/test-config.yml"));

@Before
public void setUp() {
Expand Down Expand Up @@ -197,10 +200,10 @@ public void testWithBuilderAndSystemProperties() {
assertConfig(config);
}

private static String decodeUrl(String url) {
private static String filePath(URL path) {
try {
return URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
return Paths.get(path.toURI()).toString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -234,7 +237,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 +250,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 @@ -22,7 +22,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;
Expand All @@ -41,7 +44,7 @@

public class CertUtilsTest {

private static String FABRIC8_STORE_PATH = decodeUrl(CertUtilsTest.class.getResource("/ssl/fabric8-store").getPath());
private static String FABRIC8_STORE_PATH = filePath(CertUtilsTest.class.getResource("/ssl/fabric8-store"));
private static char[] FABRIC8_STORE_PASSPHRASE = "fabric8".toCharArray();
private Properties systemProperties;

Expand Down Expand Up @@ -125,13 +128,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 = filePath(getClass().getResource("/ssl/fabric8"));
String multipleCertsPath = filePath(getClass().getResource("/ssl/multiple-certs.pem"));

KeyStore trustStore =
CertUtils.createKeyStore(null, multipleCertsPath, null, privateKeyPath, "RSA", "changeit", null, null);
Expand All @@ -156,10 +159,10 @@ private InputStream getMultipleCertsInputSteam() throws IOException {
return CertUtils.getInputStreamFromDataOrFile(null, "src/test/resources/ssl/multiple-certs.pem");
}

private static String decodeUrl(String url) {
private static String filePath(URL path) {
try {
return URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
return Paths.get(path.toURI()).toString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 54a6593

Please sign in to comment.