-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add evict(Eviction) DSL method for policy v1 Eviction resource
policy/v1 Eviction was introduced in Kubernetes 1.22.1 . There was already some work done for eviction API in #2249 Right now, we have an evict() DSL method which builds up policy/v1beta1 Eviction objecti internally. Adding evict(io.fabric8.kubernetes.api.model.policy.v1.Eviction) method to Evictable interface in order to allow use of policy/v1 Eviction. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
fc3fc4d
commit 00401de
Showing
7 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodEvictionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* 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.commons.AssumingK8sVersionAtLeast; | ||
import io.fabric8.commons.ClusterEntity; | ||
import io.fabric8.kubernetes.api.model.policy.v1.Eviction; | ||
import io.fabric8.kubernetes.api.model.policy.v1.EvictionBuilder; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.arquillian.cube.kubernetes.api.Session; | ||
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; | ||
import org.arquillian.cube.requirement.ArquillianConditionalRunner; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(ArquillianConditionalRunner.class) | ||
@RequiresKubernetes | ||
public class PodEvictionIT { | ||
|
||
@ArquillianResource | ||
public KubernetesClient client; | ||
|
||
@ArquillianResource | ||
public Session session; | ||
|
||
|
||
@ClassRule | ||
public static final AssumingK8sVersionAtLeast assumingK8sVersion = new AssumingK8sVersionAtLeast("1", "22"); | ||
|
||
@BeforeClass | ||
public static void init() { | ||
ClusterEntity.apply(PodIT.class.getResourceAsStream("/podeviction-it.yml")); | ||
} | ||
|
||
@Test | ||
public void evictWithV1PolicyEviction() { | ||
// Given | ||
String podName = "podeviction-it-with-v1-policy-eviction"; | ||
Eviction eviction = new EvictionBuilder() | ||
.withNewMetadata() | ||
.withNamespace(session.getNamespace()) | ||
.withName(podName) | ||
.endMetadata() | ||
.build(); | ||
|
||
// When | ||
boolean evicted = client.pods().inNamespace(session.getNamespace()).withName(podName).evict(eviction); | ||
|
||
// Then | ||
assertTrue(evicted); | ||
} | ||
|
||
@Test | ||
public void evictWithV1PolicyEvictionNonExistentPod() { | ||
// Given | ||
String podName = "podit-evict-non-existent-pod"; | ||
Eviction eviction = new EvictionBuilder() | ||
.withNewMetadata() | ||
.withNamespace(session.getNamespace()) | ||
.withName(podName) | ||
.endMetadata() | ||
.build(); | ||
|
||
// When | ||
boolean evicted = client.pods().inNamespace(session.getNamespace()).withName(podName).evict(eviction); | ||
|
||
// Then | ||
assertFalse(evicted); | ||
} | ||
|
||
@AfterClass | ||
public static void cleanup() { | ||
ClusterEntity.remove(NetworkPolicyIT.class.getResourceAsStream("/podeviction-it.yml")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# 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: podeviction-it-with-v1-policy-eviction | ||
spec: | ||
containers: | ||
- name: alpine | ||
image: alpine:3.13.6 | ||
command: ["sleep", "36000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters