From 9f1cc2d62cc4af6aed349ce0c785dea1d3bfa86f Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 2 Sep 2022 11:23:44 +0530 Subject: [PATCH] fix (kubernetes-itests) : Add Kubernetes 1.25.0 to E2E test suite matrix Run integration tests on Kubernetes 1.25.0 as well Signed-off-by: Rohan Kumar --- .github/workflows/e2e-tests.yml | 2 +- .../java/io/fabric8/kubernetes/CronJobIT.java | 2 + .../io/fabric8/kubernetes/PodEvictIT.java | 102 ++++++++++++++++++ .../java/io/fabric8/kubernetes/PodIT.java | 65 ----------- .../kubernetes/PodSecurityPolicyIT.java | 2 + .../src/test/resources/pod-evict-it.yml | 28 +++++ 6 files changed, 135 insertions(+), 66 deletions(-) create mode 100644 kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java create mode 100644 kubernetes-itests/src/test/resources/pod-evict-it.yml diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 555a55873ea..6c9da2933b9 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -64,7 +64,7 @@ jobs: strategy: fail-fast: false matrix: - kubernetes: [v1.24.0,v1.23.3, v1.22.6, v1.20.15, v1.19.16, v1.12.10] + kubernetes: [v1.25.0, v1.24.0, v1.23.3, v1.22.6, v1.20.15, v1.19.16, v1.12.10] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java index df20cb42454..833e4d5eb14 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java @@ -17,6 +17,7 @@ package io.fabric8.kubernetes; import io.fabric8.junit.jupiter.api.LoadKubernetesManifests; +import io.fabric8.junit.jupiter.api.RequireK8sSupport; import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob; import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobBuilder; import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobList; @@ -29,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @LoadKubernetesManifests("/cronjob-it.yml") +@RequireK8sSupport(CronJob.class) class CronJobIT { KubernetesClient client; diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java new file mode 100644 index 00000000000..86d7e4067c8 --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java @@ -0,0 +1,102 @@ +/** + * 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 io.fabric8.junit.jupiter.api.LoadKubernetesManifests; +import io.fabric8.junit.jupiter.api.RequireK8sSupport; +import io.fabric8.kubernetes.api.model.IntOrString; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.PodBuilder; +import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget; +import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetBuilder; +import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetSpecBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.readiness.Readiness; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@LoadKubernetesManifests("/pod-evict-it.yml") +@RequireK8sSupport(PodDisruptionBudget.class) +class PodEvictIT { + private static final int POD_READY_WAIT_IN_SECONDS = 60; + + KubernetesClient client; + + @Test + void evict() { + Pod pod1 = client.pods().withName("pod-standard").get(); + String pdbScope = pod1.getMetadata().getLabels().get("pdb-scope"); + assertNotNull("pdb-scope label is null. is pod1 misconfigured?", pdbScope); + + PodDisruptionBudget pdb = new PodDisruptionBudgetBuilder() + .withNewMetadata() + .withName("test-pdb") + .endMetadata() + .withSpec( + new PodDisruptionBudgetSpecBuilder() + .withMinAvailable(new IntOrString(1)) + .withNewSelector() + .addToMatchLabels("pdb-scope", pdbScope) + .endSelector() + .build()) + .build(); + + Pod pod2 = new PodBuilder() + .withNewMetadata() + .withName("pod2") + .addToLabels("pdb-scope", pdbScope) + .endMetadata() + .withSpec(pod1.getSpec()) + .build(); + + Pod pod3 = new PodBuilder() + .withNewMetadata() + .withName("pod3") + .addToLabels("pdb-scope", pdbScope) + .endMetadata() + .withSpec(pod1.getSpec()) + .build(); + + client.pods().resource(pod1).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); + + client.pods().resource(pod2).createOrReplace(); + client.pods().resource(pod2).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); + + client.resource(pdb).createOrReplace(); + + // the server needs to process the pdb before the eviction can proceed, so we'll need to wait here + await().atMost(5, TimeUnit.MINUTES) + .until(() -> client.pods().withName(pod2.getMetadata().getName()).evict()); + + // cant evict because only one left + assertFalse(client.pods().resource(pod1).evict()); + // ensure it really is still up + assertTrue(Readiness.getInstance().isReady(client.pods().resource(pod1).fromServer().get())); + + // create another pod to satisfy PDB + client.pods().resource(pod3).createOrReplace(); + client.pods().resource(pod3).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); + + // can now evict + assertTrue(client.pods().resource(pod3).evict()); + } +} diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java index 7bb401bc22e..338d44b2444 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java @@ -18,20 +18,15 @@ import io.fabric8.junit.jupiter.api.LoadKubernetesManifests; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.api.model.IntOrString; import io.fabric8.kubernetes.api.model.Namespace; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodBuilder; import io.fabric8.kubernetes.api.model.PodList; import io.fabric8.kubernetes.api.model.Status; -import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget; -import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetBuilder; -import io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetSpecBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.ExecListener; import io.fabric8.kubernetes.client.dsl.ExecWatch; import io.fabric8.kubernetes.client.dsl.PodResource; -import io.fabric8.kubernetes.client.readiness.Readiness; import io.fabric8.kubernetes.client.utils.InputStreamPumper; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; @@ -57,7 +52,6 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -106,65 +100,6 @@ void delete() { assertTrue(client.pods().withName("pod-delete").delete().size() == 1); } - @Test - void evict() { - Pod pod1 = client.pods().withName("pod-standard").get(); - String pdbScope = pod1.getMetadata().getLabels().get("pdb-scope"); - assertNotNull("pdb-scope label is null. is pod1 misconfigured?", pdbScope); - - PodDisruptionBudget pdb = new PodDisruptionBudgetBuilder() - .withNewMetadata() - .withName("test-pdb") - .endMetadata() - .withSpec( - new PodDisruptionBudgetSpecBuilder() - .withMinAvailable(new IntOrString(1)) - .withNewSelector() - .addToMatchLabels("pdb-scope", pdbScope) - .endSelector() - .build()) - .build(); - - Pod pod2 = new PodBuilder() - .withNewMetadata() - .withName("pod2") - .addToLabels("pdb-scope", pdbScope) - .endMetadata() - .withSpec(pod1.getSpec()) - .build(); - - Pod pod3 = new PodBuilder() - .withNewMetadata() - .withName("pod3") - .addToLabels("pdb-scope", pdbScope) - .endMetadata() - .withSpec(pod1.getSpec()) - .build(); - - client.pods().resource(pod1).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); - - client.pods().resource(pod2).createOrReplace(); - client.pods().resource(pod2).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); - - client.resource(pdb).createOrReplace(); - - // the server needs to process the pdb before the eviction can proceed, so we'll need to wait here - await().atMost(5, TimeUnit.MINUTES) - .until(() -> client.pods().withName(pod2.getMetadata().getName()).evict()); - - // cant evict because only one left - assertFalse(client.pods().resource(pod1).evict()); - // ensure it really is still up - assertTrue(Readiness.getInstance().isReady(client.pods().resource(pod1).fromServer().get())); - - // create another pod to satisfy PDB - client.pods().resource(pod3).createOrReplace(); - client.pods().resource(pod3).waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); - - // can now evict - assertTrue(client.pods().resource(pod3).evict()); - } - @Test void log() { client.pods().withName("pod-standard").waitUntilReady(POD_READY_WAIT_IN_SECONDS, TimeUnit.SECONDS); diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java index 8b17ea1771e..b84a0649296 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java @@ -17,6 +17,7 @@ package io.fabric8.kubernetes; import io.fabric8.junit.jupiter.api.LoadKubernetesManifests; +import io.fabric8.junit.jupiter.api.RequireK8sSupport; import io.fabric8.kubernetes.api.model.policy.v1beta1.PodSecurityPolicy; import io.fabric8.kubernetes.api.model.policy.v1beta1.PodSecurityPolicyBuilder; import io.fabric8.kubernetes.api.model.policy.v1beta1.PodSecurityPolicyList; @@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @LoadKubernetesManifests("/podsecuritypolicy-it.yml") +@RequireK8sSupport(PodSecurityPolicy.class) class PodSecurityPolicyIT { KubernetesClient client; diff --git a/kubernetes-itests/src/test/resources/pod-evict-it.yml b/kubernetes-itests/src/test/resources/pod-evict-it.yml new file mode 100644 index 00000000000..358f806efed --- /dev/null +++ b/kubernetes-itests/src/test/resources/pod-evict-it.yml @@ -0,0 +1,28 @@ +# +# 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. +# + +--- +apiVersion: v1 +kind: Pod +metadata: + name: pod-standard + labels: + pdb-scope: get +spec: + containers: + - name: busybox + image: busybox + command: ["sleep", "36000"]