From ac1b2605a5889f8ead73d7b39adc01b5b47043f0 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Fri, 19 Nov 2021 11:48:19 -0800 Subject: [PATCH 1/5] Add windows and macos to the build matrix. --- .github/workflows/maven.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index da53774c2b..ce70a7c208 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,12 +23,13 @@ jobs: - name: Verify Format and License run: mvn spotless:check build: - runs-on: ubuntu-latest name: Java ${{ matrix.java }} Maven Test strategy: matrix: # Test against the LTS Java versions. TODO: add JDK18 when it becomes available. java: [ 8.0.x, 11.0.x, 17.0.x ] + os: [ windows-latest, macos-latest, ubuntu-latest ] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2.4.0 - name: Setup Java @@ -41,11 +42,9 @@ jobs: with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ matrix.java }}-${{ hashFiles('pom.xml', '**/pom.xml') }} - - name: Buid with Maven + - name: Build with Maven run: | - sudo mvn clean test \ - -q \ - -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + mvn clean test -q -B --define=org.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn build-graalvm: runs-on: ubuntu-latest name: GraalVM Maven Test From bad85c56475237e14df47185260a5149b2e8caad Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Mon, 22 Nov 2021 10:35:54 -0800 Subject: [PATCH 2/5] Temporarily only run Java 8 --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ce70a7c208..1d29f6d2e5 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: # Test against the LTS Java versions. TODO: add JDK18 when it becomes available. - java: [ 8.0.x, 11.0.x, 17.0.x ] + java: [ 8.0.x ] os: [ windows-latest, macos-latest, ubuntu-latest ] runs-on: ${{ matrix.os }} steps: From 5ea971f8e9acca6d4bbac0c74c6a74ecb0c4f299 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Mon, 22 Nov 2021 16:25:43 -0800 Subject: [PATCH 3/5] Fix tests for Windows. --- .github/workflows/maven.yml | 4 +- .../extended/kubectl/KubectlApplyTest.java | 15 ++++-- .../extended/kubectl/KubectlCreateTest.java | 15 ++++-- .../extended/kubectl/KubectlDrainTest.java | 4 +- .../extended/kubectl/KubectlPatchTest.java | 14 +++-- .../extended/kubectl/KubectlRolloutTest.java | 51 ++++++++++++++----- .../util/deployment/DeploymentHelperTest.java | 11 +++- .../client/extended/pager/PagerTest.java | 16 ++++-- .../KubernetesFromYamlProcessor.java | 4 +- .../main/java/io/kubernetes/client/Copy.java | 1 + .../kubernetes/client/util/ClientBuilder.java | 1 - .../client/util/ClientBuilderTest.java | 9 +++- .../io/kubernetes/client/util/ConfigTest.java | 2 + .../client/util/KubeConfigTest.java | 18 +++++++ .../kubernetes/client/util/SSLUtilsTest.java | 10 ++-- .../io/kubernetes/client/util/YamlTest.java | 6 +-- .../ClientCertificateAuthenticationTest.java | 19 ++++--- .../TokenFileAuthenticationTest.java | 5 +- .../util/generic/dynamic/DynamicsTest.java | 7 ++- 19 files changed, 156 insertions(+), 56 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1d29f6d2e5..020c70ae68 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,8 +27,8 @@ jobs: strategy: matrix: # Test against the LTS Java versions. TODO: add JDK18 when it becomes available. - java: [ 8.0.x ] - os: [ windows-latest, macos-latest, ubuntu-latest ] + java: [ 8.0.x, 11.0.x, 17.0.x ] + os: [ windows-latest, ubuntu-latest ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2.4.0 diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlApplyTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlApplyTest.java index 32408b72c1..a47010eff2 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlApplyTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlApplyTest.java @@ -38,13 +38,22 @@ public class KubectlApplyTest { private static final String DISCOVERY_API = - KubectlApplyTest.class.getClassLoader().getResource("discovery-api.json").getPath(); + new java.io.File( + KubectlApplyTest.class.getClassLoader().getResource("discovery-api.json").getPath()) + .toString(); private static final String DISCOVERY_APIV1 = - KubectlApplyTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath(); + new java.io.File( + KubectlApplyTest.class + .getClassLoader() + .getResource("discovery-api-v1.json") + .getPath()) + .toString(); private static final String DISCOVERY_APIS = - KubectlApplyTest.class.getClassLoader().getResource("discovery-apis.json").getPath(); + new java.io.File( + KubectlApplyTest.class.getClassLoader().getResource("discovery-apis.json").getPath()) + .toString(); private ApiClient apiClient; diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlCreateTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlCreateTest.java index 860d986b36..0011b3b21a 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlCreateTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlCreateTest.java @@ -21,6 +21,7 @@ import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.util.ClientBuilder; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -32,13 +33,21 @@ public class KubectlCreateTest { private static final String DISCOVERY_API = - KubectlCreateTest.class.getClassLoader().getResource("discovery-api.json").getPath(); + new File(KubectlCreateTest.class.getClassLoader().getResource("discovery-api.json").getPath()) + .toString(); private static final String DISCOVERY_APIV1 = - KubectlCreateTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath(); + new File( + KubectlCreateTest.class + .getClassLoader() + .getResource("discovery-api-v1.json") + .getPath()) + .toString(); private static final String DISCOVERY_APIS = - KubectlCreateTest.class.getClassLoader().getResource("discovery-apis.json").getPath(); + new File( + KubectlCreateTest.class.getClassLoader().getResource("discovery-apis.json").getPath()) + .toString(); private ApiClient apiClient; diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlDrainTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlDrainTest.java index b147a3ba6a..aece9ee852 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlDrainTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlDrainTest.java @@ -31,6 +31,7 @@ import io.kubernetes.client.openapi.models.V1Pod; import io.kubernetes.client.util.ClientBuilder; import io.kubernetes.client.util.ModelMapper; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -41,7 +42,8 @@ public class KubectlDrainTest { private static final String POD_LIST_API = - KubectlDrainTest.class.getClassLoader().getResource("pod-list.json").getPath(); + new File(KubectlDrainTest.class.getClassLoader().getResource("pod-list.json").getPath()) + .toString(); private ApiClient apiClient; diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlPatchTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlPatchTest.java index 13e4182223..f7a9cf778e 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlPatchTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlPatchTest.java @@ -27,6 +27,7 @@ import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.util.ClientBuilder; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -37,13 +38,20 @@ public class KubectlPatchTest { private static final String DISCOVERY_API = - KubectlPatchTest.class.getClassLoader().getResource("discovery-api.json").getPath(); + new File(KubectlPatchTest.class.getClassLoader().getResource("discovery-api.json").getPath()) + .toString(); private static final String DISCOVERY_APIV1 = - KubectlPatchTest.class.getClassLoader().getResource("discovery-api-v1.json").getPath(); + new File( + KubectlPatchTest.class + .getClassLoader() + .getResource("discovery-api-v1.json") + .getPath()) + .toString(); private static final String DISCOVERY_APIS = - KubectlPatchTest.class.getClassLoader().getResource("discovery-apis.json").getPath(); + new File(KubectlPatchTest.class.getClassLoader().getResource("discovery-apis.json").getPath()) + .toString(); private ApiClient apiClient; diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutTest.java index b6239a3e25..0d95c3a6b6 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutTest.java @@ -34,6 +34,7 @@ import io.kubernetes.client.openapi.models.V1StatefulSetList; import io.kubernetes.client.util.ClientBuilder; import io.kubernetes.client.util.ModelMapper; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -50,34 +51,56 @@ public class KubectlRolloutTest { @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); private static final String DEPLOYMENT = - KubectlRolloutTest.class.getClassLoader().getResource("deployment.json").getPath(); + new File(KubectlRolloutTest.class.getClassLoader().getResource("deployment.json").getPath()) + .toString(); private static final String REPLICASET_LIST = - KubectlRolloutTest.class.getClassLoader().getResource("replicaset-list.json").getPath(); + new File( + KubectlRolloutTest.class + .getClassLoader() + .getResource("replicaset-list.json") + .getPath()) + .toString(); private static final String DAEMON_SET = - KubectlRolloutTest.class.getClassLoader().getResource("daemonset.json").getPath(); + new File(KubectlRolloutTest.class.getClassLoader().getResource("daemonset.json").getPath()) + .toString(); private static final String PATCHED_DAEMON_SET = - KubectlRolloutTest.class.getClassLoader().getResource("patched-daemonset.json").getPath(); + new File( + KubectlRolloutTest.class + .getClassLoader() + .getResource("patched-daemonset.json") + .getPath()) + .toString(); private static final String DAEMON_SET_CONTROLLER_REVISION_LIST = - KubectlRolloutTest.class - .getClassLoader() - .getResource("daemonset-controllerrevision-list.json") - .getPath(); + new File( + KubectlRolloutTest.class + .getClassLoader() + .getResource("daemonset-controllerrevision-list.json") + .getPath()) + .toString(); private static final String STATEFUL_SET = - KubectlRolloutTest.class.getClassLoader().getResource("statefulset.json").getPath(); + new File(KubectlRolloutTest.class.getClassLoader().getResource("statefulset.json").getPath()) + .toString(); private static final String PATCHED_STATEFUL_SET = - KubectlRolloutTest.class.getClassLoader().getResource("patched-statefulset.json").getPath(); + new File( + KubectlRolloutTest.class + .getClassLoader() + .getResource("patched-statefulset.json") + .getPath()) + .toString(); private static final String STATEFUL_SET_CONTROLLER_REVISION_LIST = - KubectlRolloutTest.class - .getClassLoader() - .getResource("statefulset-controllerrevision-list.json") - .getPath(); + new File( + KubectlRolloutTest.class + .getClassLoader() + .getResource("statefulset-controllerrevision-list.json") + .getPath()) + .toString(); @Before public void setup() throws IOException { diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelperTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelperTest.java index 773d1a2e9b..efa62a20af 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelperTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelperTest.java @@ -28,6 +28,7 @@ import io.kubernetes.client.openapi.models.V1ReplicaSet; import io.kubernetes.client.openapi.models.V1ReplicaSetList; import io.kubernetes.client.util.ClientBuilder; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -46,10 +47,16 @@ public class DeploymentHelperTest { @Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort(), false); private static final String DEPLOYMENT = - DeploymentHelperTest.class.getClassLoader().getResource("deployment.json").getPath(); + new File(DeploymentHelperTest.class.getClassLoader().getResource("deployment.json").getPath()) + .toString(); private static final String REPLICASET_LIST = - DeploymentHelperTest.class.getClassLoader().getResource("replicaset-list.json").getPath(); + new File( + DeploymentHelperTest.class + .getClassLoader() + .getResource("replicaset-list.json") + .getPath()) + .toString(); @Before public void setup() throws IOException { diff --git a/extended/src/test/java/io/kubernetes/client/extended/pager/PagerTest.java b/extended/src/test/java/io/kubernetes/client/extended/pager/PagerTest.java index 36ded23a48..0ae56452f6 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/pager/PagerTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/pager/PagerTest.java @@ -30,6 +30,7 @@ import io.kubernetes.client.openapi.models.V1Namespace; import io.kubernetes.client.openapi.models.V1NamespaceList; import io.kubernetes.client.util.ClientBuilder; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -46,15 +47,20 @@ public class PagerTest { private ApiClient client; private static final String LIST_PAGE0_FILE_PATH = - PagerTest.class.getClassLoader().getResource("namespace-list-pager0.json").getPath(); + new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager0.json").getPath()) + .toString(); private static final String LIST_PAGE1_FILE_PATH = - PagerTest.class.getClassLoader().getResource("namespace-list-pager1.json").getPath(); + new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager1.json").getPath()) + .toString(); private static final String LIST_PAGE2_FILE_PATH = - PagerTest.class.getClassLoader().getResource("namespace-list-pager2.json").getPath(); + new File(PagerTest.class.getClassLoader().getResource("namespace-list-pager2.json").getPath()) + .toString(); private static final String LIST_STATUS_FILE_PATH = - PagerTest.class.getClassLoader().getResource("status-400.json").getPath(); + new File(PagerTest.class.getClassLoader().getResource("status-400.json").getPath()) + .toString(); private static final String STATUS_BAD_TOKEN_FILE_PATH = - PagerTest.class.getClassLoader().getResource("bad-token-status.json").getPath(); + new File(PagerTest.class.getClassLoader().getResource("bad-token-status.json").getPath()) + .toString(); @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); @Before diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromYamlProcessor.java b/spring/src/main/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromYamlProcessor.java index 42922d61f4..a11da9bd38 100644 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromYamlProcessor.java +++ b/spring/src/main/java/io/kubernetes/client/spring/extended/manifests/KubernetesFromYamlProcessor.java @@ -14,6 +14,7 @@ import io.kubernetes.client.spring.extended.manifests.annotation.FromYaml; import io.kubernetes.client.util.Yaml; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.Files; @@ -91,7 +92,8 @@ private Object loadFromYaml(String targetFilePath) { Path targetPath = Paths.get(targetFilePath); if (!Files.exists(Paths.get(targetFilePath))) { // checks if it exists on the machine // otherwise use load from classpath resources - Path classPath = Paths.get(getClass().getClassLoader().getResource(targetFilePath).getPath()); + Path classPath = + new File(getClass().getClassLoader().getResource(targetFilePath).getFile()).toPath(); if (Files.exists(classPath)) { // use classpath it works targetPath = classPath; } else { diff --git a/util/src/main/java/io/kubernetes/client/Copy.java b/util/src/main/java/io/kubernetes/client/Copy.java index a4f90b46fb..66d5acf3e0 100644 --- a/util/src/main/java/io/kubernetes/client/Copy.java +++ b/util/src/main/java/io/kubernetes/client/Copy.java @@ -411,6 +411,7 @@ public Future copyFileToPodAsync( private Process execCopyToPod(String namespace, String pod, String container, Path destPath) throws ApiException, IOException { + // TODO: This assumes Linux and won't work on Windows Containers (for many reasons...) String parentPath = destPath.getParent() != null ? destPath.getParent().toString() : "."; parentPath = parentPath.replace("\\", "/"); return this.exec( diff --git a/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java b/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java index 181b6c4a90..024d428376 100644 --- a/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java +++ b/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java @@ -140,7 +140,6 @@ private static File findConfigFromEnv() { if (kubeConfigPath == null) { return null; } - final File kubeConfig = new File(kubeConfigPath); if (kubeConfig.exists()) { return kubeConfig; diff --git a/util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java b/util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java index 29614ed836..8d031dd475 100644 --- a/util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java +++ b/util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java @@ -46,9 +46,10 @@ public class ClientBuilderTest { Resources.getResource("kubeconfig-https").getPath(); private static final String KUBECONFIG_HTTPS_X509_FILE_PATH = Resources.getResource("kubeconfig-https-x509").getPath(); - private static final String SSL_CA_CERT_PATH = Resources.getResource("ca-cert.pem").getPath(); + private static final String SSL_CA_CERT_PATH = + new File(Resources.getResource("ca-cert.pem").getPath()).toString(); private static final String INVALID_SSL_CA_CERT_PATH = - Resources.getResource("ca-cert-invalid.pem").getPath(); + new File(Resources.getResource("ca-cert-invalid.pem").getPath()).toString(); private String basePath = "http://localhost"; private String apiKey = "ABCD"; @@ -62,6 +63,8 @@ public class ClientBuilderTest { public void testDefaultClientWithNoFiles() throws Exception { String path = withEnvironmentVariable("HOME", "/non-existent") + .and("HOMEDRIVE", null) + .and("USERPROFILE", null) .and("KUBECONFIG", null) .execute( () -> { @@ -139,6 +142,8 @@ public void testInvalidKubeconfig() throws Exception { String path = withEnvironmentVariable("KUBECONFIG", "/non-existent") .and("HOME", "/none-existent") + .and("HOMEDRIVE", null) + .and("USERPROFILE", null) .execute( () -> { final ApiClient client = ClientBuilder.standard().build(); diff --git a/util/src/test/java/io/kubernetes/client/util/ConfigTest.java b/util/src/test/java/io/kubernetes/client/util/ConfigTest.java index c0ab7ff55c..1934ad3fdd 100644 --- a/util/src/test/java/io/kubernetes/client/util/ConfigTest.java +++ b/util/src/test/java/io/kubernetes/client/util/ConfigTest.java @@ -33,6 +33,8 @@ public void testDefaultClientNothingPresent() { try { String path = withEnvironmentVariable("HOME", "/non-existent") + .and("HOMEDRIVE", null) + .and("USERPROFILE", null) .execute( () -> { ApiClient client = Config.defaultClient(); diff --git a/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java b/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java index 53c0c51fcc..1dbf180bd8 100644 --- a/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java +++ b/util/src/test/java/io/kubernetes/client/util/KubeConfigTest.java @@ -315,6 +315,10 @@ public void testRefreshToken() { @Test public void testExecCredentials() throws Exception { + // TODO: test exec on Windows + if (System.getProperty("os.name").contains("Windows")) { + return; + } KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_EXEC)); kc.setFile(folder.newFile()); // just making sure it is ignored assertEquals("abc123", kc.getAccessToken()); @@ -322,6 +326,10 @@ public void testExecCredentials() throws Exception { @Test public void testExecCredentialsAlpha1() throws Exception { + // TODO: test exec on Windows + if (System.getProperty("os.name").contains("Windows")) { + return; + } KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_EXEC.replace("v1beta1", "v1alpha1"))); assertEquals("abc123", kc.getAccessToken()); @@ -350,6 +358,11 @@ public void testExecCredentialsAlpha1() throws Exception { @Test public void testExecCredentialsEnv() throws Exception { + // TODO: test exec on Windows + if (System.getProperty("os.name").contains("Windows")) { + return; + } + KubeConfig kc = KubeConfig.loadKubeConfig(new StringReader(KUBECONFIG_EXEC_ENV)); assertEquals("abc123", kc.getAccessToken()); } @@ -374,6 +387,11 @@ public void testExecCredentialsEnv() throws Exception { @Test public void testExecCredentialsBasedir() throws Exception { + // TODO: test exec on Windows + if (System.getProperty("os.name").contains("Windows")) { + return; + } + File basedir = folder.newFolder(); File config = new File(basedir, ".kubeconfig"); try (FileWriter writer = new FileWriter(config)) { diff --git a/util/src/test/java/io/kubernetes/client/util/SSLUtilsTest.java b/util/src/test/java/io/kubernetes/client/util/SSLUtilsTest.java index 2a58739b3b..bb9b0ad9fb 100644 --- a/util/src/test/java/io/kubernetes/client/util/SSLUtilsTest.java +++ b/util/src/test/java/io/kubernetes/client/util/SSLUtilsTest.java @@ -13,6 +13,7 @@ package io.kubernetes.client.util; import io.kubernetes.client.Resources; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -23,15 +24,16 @@ public class SSLUtilsTest extends TestCase { - private static final String CLIENT_KEY_PATH = Resources.getResource("clientauth.key").getPath(); + private static final String CLIENT_KEY_PATH = + new File(Resources.getResource("clientauth.key").getPath()).toString(); private static final String CLIENT_KEY_RSA_PATH = - Resources.getResource("clientauth-rsa.key").getPath(); + new File(Resources.getResource("clientauth-rsa.key").getPath()).toString(); private static final String CLIENT_KEY_EC_PATH = - Resources.getResource("clientauth-ec.key").getPath(); + new File(Resources.getResource("clientauth-ec.key").getPath()).toString(); public void testPKCS8KeyLoadDump() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { - byte[] loaded = Files.readAllBytes(Paths.get(CLIENT_KEY_PATH)); + byte[] loaded = Files.readAllBytes(Paths.get(CLIENT_KEY_PATH.replace("C:/", ""))); PrivateKey privateKey = SSLUtils.loadKey(loaded); byte[] dumped = SSLUtils.dumpKey(privateKey); PrivateKey reloaded = SSLUtils.loadKey(dumped); diff --git a/util/src/test/java/io/kubernetes/client/util/YamlTest.java b/util/src/test/java/io/kubernetes/client/util/YamlTest.java index e62efa28ab..a27ccf2969 100644 --- a/util/src/test/java/io/kubernetes/client/util/YamlTest.java +++ b/util/src/test/java/io/kubernetes/client/util/YamlTest.java @@ -43,7 +43,7 @@ public class YamlTest { private static final URL TEST_YAML_FILE = Resources.getResource("test.yaml"); - private static final String TEST_YAML_FILE_PATH = TEST_YAML_FILE.getPath(); + private static final String TEST_YAML_FILE_PATH = new File(TEST_YAML_FILE.getPath()).toString(); private static final URL EXPECTED_YAML_FILE = Resources.getResource("expected.yaml"); @@ -160,7 +160,7 @@ public void testLoadAllFile() throws Exception { } } String result = Yaml.dumpAll(k8ObjectList.iterator()); - String expected = Resources.toString(EXPECTED_YAML_FILE, UTF_8); + String expected = Resources.toString(EXPECTED_YAML_FILE, UTF_8).replace("\r\n", "\n"); assertThat(result, equalTo(expected)); } @@ -287,7 +287,7 @@ public void testLoadAsYamlCantConstructObjects() { @Test public void testLoadDumpCRDWithIntOrStringExtension() { - String data = Resources.toString(CRD_INT_OR_STRING_FILE, UTF_8); + String data = Resources.toString(CRD_INT_OR_STRING_FILE, UTF_8).replace("\r\n", "\n"); V1CustomResourceDefinition crd = Yaml.loadAs(data, V1CustomResourceDefinition.class); assertNotNull(crd); assertTrue( diff --git a/util/src/test/java/io/kubernetes/client/util/credentials/ClientCertificateAuthenticationTest.java b/util/src/test/java/io/kubernetes/client/util/credentials/ClientCertificateAuthenticationTest.java index 78f5b6c0de..8f87a2490e 100644 --- a/util/src/test/java/io/kubernetes/client/util/credentials/ClientCertificateAuthenticationTest.java +++ b/util/src/test/java/io/kubernetes/client/util/credentials/ClientCertificateAuthenticationTest.java @@ -14,31 +14,34 @@ import io.kubernetes.client.Resources; import io.kubernetes.client.openapi.ApiClient; +import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import org.junit.Test; public class ClientCertificateAuthenticationTest { - private static final String CLIENT_CERT_PATH = Resources.getResource("clientauth.cert").getPath(); + private static final String CLIENT_CERT_PATH = + new File(Resources.getResource("clientauth.cert").getPath()).toString(); private static final String CLIENT_EC_CERT_PATH = - Resources.getResource("clientauth-ec.cert").getPath(); + new File(Resources.getResource("clientauth-ec.cert").getPath()).toString(); // RSA key in PKCS8 format - private static final String CLIENT_KEY_PATH = Resources.getResource("clientauth.key").getPath(); + private static final String CLIENT_KEY_PATH = + new File(Resources.getResource("clientauth.key").getPath()).toString(); // EC key in PKCS8 format private static final String CLIENT_EC_KEY_PATH = - Resources.getResource("clientauth-ec-fixed.key").getPath(); + new File(Resources.getResource("clientauth-ec-fixed.key").getPath()).toString(); // RSA key in PKCS1 format private static final String CLIENT_KEY_OLD_PATH = - Resources.getResource("clientauth-rsa.key").getPath(); + new File(Resources.getResource("clientauth-rsa.key").getPath()).toString(); // EC key in PKCS7 format private static final String CLIENT_EC_KEY_OLD_PATH = - Resources.getResource("clientauth-ec.key").getPath(); + new File(Resources.getResource("clientauth-ec.key").getPath()).toString(); private static final String CLIENT_CERT_CHAIN_PATH = - Resources.getResource("clientauth-chain.cert").getPath(); + new File(Resources.getResource("clientauth-chain.cert").getPath()).toString(); private static final String CLIENT_CERT_CHAIN_KEY_PATH = - Resources.getResource("clientauth-chain.key").getPath(); + new File(Resources.getResource("clientauth-chain.key").getPath()).toString(); @Test public void testValidCertificates() throws Exception { diff --git a/util/src/test/java/io/kubernetes/client/util/credentials/TokenFileAuthenticationTest.java b/util/src/test/java/io/kubernetes/client/util/credentials/TokenFileAuthenticationTest.java index d920ecaf78..0ff3c7e05b 100644 --- a/util/src/test/java/io/kubernetes/client/util/credentials/TokenFileAuthenticationTest.java +++ b/util/src/test/java/io/kubernetes/client/util/credentials/TokenFileAuthenticationTest.java @@ -27,6 +27,7 @@ import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.apis.CoreV1Api; +import java.io.File; import java.io.IOException; import java.time.Instant; import org.junit.Before; @@ -35,9 +36,9 @@ public class TokenFileAuthenticationTest { private static final String SERVICEACCOUNT_TOKEN1_PATH = - Resources.getResource("token1").getPath(); + new File(Resources.getResource("token1").getPath()).toString(); private static final String SERVICEACCOUNT_TOKEN2_PATH = - Resources.getResource("token2").getPath(); + new File(Resources.getResource("token2").getPath()).toString(); private static final int PORT = 8089; private TokenFileAuthentication auth; diff --git a/util/src/test/java/io/kubernetes/client/util/generic/dynamic/DynamicsTest.java b/util/src/test/java/io/kubernetes/client/util/generic/dynamic/DynamicsTest.java index b98959eb40..c56d006e70 100644 --- a/util/src/test/java/io/kubernetes/client/util/generic/dynamic/DynamicsTest.java +++ b/util/src/test/java/io/kubernetes/client/util/generic/dynamic/DynamicsTest.java @@ -18,6 +18,7 @@ import io.kubernetes.client.Resources; import io.kubernetes.client.openapi.JSON; import io.kubernetes.client.util.Yaml; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -25,9 +26,11 @@ public class DynamicsTest { - private static final String TEST_POD_YAML_FILE = Resources.getResource("test-pod.yaml").getPath(); + private static final String TEST_POD_YAML_FILE = + new File(Resources.getResource("test-pod.yaml").getPath()).toString(); - private static final String TEST_POD_JSON_FILE = Resources.getResource("test-pod.json").getPath(); + private static final String TEST_POD_JSON_FILE = + new File(Resources.getResource("test-pod.json").getPath()).toString(); private JSON json = new JSON(); From 38c553aabe1a45f0809cfff1fc6154a3c2bfda4d Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 24 Nov 2021 07:44:28 -0800 Subject: [PATCH 4/5] Fix pom for JDK17 --- extended/pom.xml | 61 +++++++++++++++++++++++++++++++++++++----------- spring/pom.xml | 2 +- util/pom.xml | 4 +++- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/extended/pom.xml b/extended/pom.xml index 82bddaf96d..29ab9c4174 100644 --- a/extended/pom.xml +++ b/extended/pom.xml @@ -113,19 +113,54 @@ 8 - - org.apache.maven.plugins - maven-surefire-plugin - - @{argLine} -Xms512m -Xmx1500m - methods - false - 1 - 1 - false - - - + + + surefire-newerJava + + (1.8,) + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + @{argLine} -Xms512m -Xmx1500m --illegal-access=warn --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED + + methods + false + 1 + 1 + false + + + + + + + surefire-java8 + + 1.8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + @{argLine} -Xms512m -Xmx1500m + methods + false + 1 + 1 + false + + + + + + diff --git a/spring/pom.xml b/spring/pom.xml index 802e21fc4a..7378a8fb08 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -121,7 +121,7 @@ org.apache.maven.plugins maven-surefire-plugin - @{argLine} -Xms512m -Xmx1500m --illegal-access=warn + @{argLine} -Xms512m -Xmx1500m --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED methods false 1 diff --git a/util/pom.xml b/util/pom.xml index a8ff834cbc..002d42dfcc 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -166,7 +166,9 @@ org.apache.maven.plugins maven-surefire-plugin - @{argLine} -Xms512m -Xmx1500m --illegal-access=warn + + @{argLine} -Xms512m -Xmx1500m --illegal-access=warn --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED + methods false 1 From cadf986b8e168cbc1c087ac73df8f35777912ffe Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 24 Nov 2021 13:54:16 -0800 Subject: [PATCH 5/5] Fix racy test --- .../workqueue/DefaultDelayingQueue.java | 21 ++++++++++++++----- .../workqueue/DefaultDelayingQueueTest.java | 18 +++++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueue.java b/extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueue.java index b769be25a6..7beafa94da 100644 --- a/extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueue.java +++ b/extended/src/main/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueue.java @@ -25,6 +25,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; /** The default delaying queue implementation. */ public class DefaultDelayingQueue extends DefaultWorkQueue implements DelayingQueue { @@ -34,8 +35,10 @@ public class DefaultDelayingQueue extends DefaultWorkQueue implements Dela private DelayQueue> delayQueue; private ConcurrentMap> waitingEntryByData; protected BlockingQueue> waitingForAddQueue; + private Supplier timeSource; public DefaultDelayingQueue(ExecutorService waitingWorker) { + this.timeSource = Instant::now; this.delayQueue = new DelayQueue<>(); this.waitingEntryByData = new ConcurrentHashMap<>(); this.waitingForAddQueue = new LinkedBlockingQueue<>(1000); @@ -57,10 +60,16 @@ public void addAfter(T item, Duration duration) { super.add(item); return; } - WaitForEntry entry = new WaitForEntry<>(item, duration.addTo(Instant.now())); + WaitForEntry entry = + new WaitForEntry<>(item, duration.addTo(this.timeSource.get()), this.timeSource); this.waitingForAddQueue.offer(entry); } + // Visible for testing + protected void injectTimeSource(Supplier fn) { + this.timeSource = fn; + } + private void waitingLoop() { try { while (true) { @@ -78,7 +87,7 @@ private void waitingLoop() { // a. if ready, remove it from the delay-queue and push it into underlying // work-queue // b. if not, refresh the next ready-at time. - Instant now = Instant.now(); + Instant now = this.timeSource.get(); if (!Duration.between(entry.readyAtMillis, now).isNegative()) { delayQueue.remove(entry); super.add(entry.data); @@ -92,7 +101,7 @@ private void waitingLoop() { WaitForEntry waitForEntry = waitingForAddQueue.poll(nextReadyAt.toMillis(), TimeUnit.MILLISECONDS); if (waitForEntry != null) { - if (Duration.between(waitForEntry.readyAtMillis, Instant.now()).isNegative()) { + if (Duration.between(waitForEntry.readyAtMillis, this.timeSource.get()).isNegative()) { // the item is not yet ready, insert it to the delay-queue insert(this.delayQueue, this.waitingEntryByData, waitForEntry); } else { @@ -126,17 +135,19 @@ private void insert( // WaitForEntry holds the data to add and the time it should be added. private static class WaitForEntry implements Delayed { - private WaitForEntry(T data, Temporal readyAtMillis) { + private WaitForEntry(T data, Temporal readyAtMillis, Supplier timeSource) { this.data = data; this.readyAtMillis = readyAtMillis; + this.timeSource = timeSource; } private T data; private Temporal readyAtMillis; + private Supplier timeSource; @Override public long getDelay(TimeUnit unit) { - Duration duration = Duration.between(Instant.now(), readyAtMillis); + Duration duration = Duration.between(this.timeSource.get(), readyAtMillis); return unit.convert(duration.toMillis(), TimeUnit.MILLISECONDS); } diff --git a/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueueTest.java b/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueueTest.java index 58e030d64e..e7df100d66 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueueTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/workqueue/DefaultDelayingQueueTest.java @@ -17,25 +17,37 @@ import io.kubernetes.client.extended.wait.Wait; import java.time.Duration; +import java.time.Instant; import org.junit.Test; public class DefaultDelayingQueueTest { @Test public void testSimpleDelayingQueue() throws Exception { + final Instant staticTime = Instant.now(); DefaultDelayingQueue queue = new DefaultDelayingQueue<>(); + // Hold time still + queue.injectTimeSource( + () -> { + return staticTime; + }); queue.addAfter("foo", Duration.ofMillis(50)); + // Verify that we haven't released it assertTrue(waitForWaitingQueueToFill(queue)); - assertTrue(queue.length() == 0); + assertEquals(queue.length(), 0); - Thread.sleep(60L); + // Advance time + queue.injectTimeSource( + () -> { + return staticTime.plusMillis(100); + }); assertTrue(waitForAdded(queue, 1)); String item = queue.get(); queue.done(item); Thread.sleep(10 * 1000L); - assertTrue(queue.length() == 0); + assertEquals(queue.length(), 0); } @Test