Skip to content

Commit

Permalink
fix (kubernetes-itests) : Add Kubernetes 1.25.0 to E2E test suite matrix
Browse files Browse the repository at this point in the history
Run integration tests on Kubernetes 1.25.0 as well

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Sep 7, 2022
1 parent 8125874 commit f977a14
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@LoadKubernetesManifests("/cronjob-it.yml")
@RequireK8sSupport(CronJob.class)
class CronJobIT {

KubernetesClient client;
Expand Down
102 changes: 102 additions & 0 deletions kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictIT.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
65 changes: 0 additions & 65 deletions kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@LoadKubernetesManifests("/podsecuritypolicy-it.yml")
@RequireK8sSupport(PodSecurityPolicy.class)
class PodSecurityPolicyIT {

KubernetesClient client;
Expand Down
28 changes: 28 additions & 0 deletions kubernetes-itests/src/test/resources/pod-evict-it.yml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit f977a14

Please sign in to comment.