io.fabric8.kubernetes.api.model.policy.PodDisruptionBudgetBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.policy.PodDisruptionBudgetBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RabbitMQClusterFactory.java From rabbitmq-operator with Apache License 2.0 | 6 votes |
private PodDisruptionBudget buildPodDisruptionBudget(final RabbitMQCustomResource resource) { final String namespace = resource.getMetadata().getNamespace(); return new PodDisruptionBudgetBuilder() .withNewMetadata() .withName(String.format("%s-poddisruptionbudget", resource.getName())) .withNamespace(namespace) .withOwnerReferences( new OwnerReference( resource.getApiVersion(), true, true, resource.getKind(), resource.getName(), resource.getMetadata().getUid() ) ) .endMetadata() .withNewSpec() .withMaxUnavailable(new IntOrString(1)) .withNewSelector() .withMatchLabels(Collections.singletonMap(Labels.Kubernetes.INSTANCE, resource.getName())) .endSelector() .endSpec() .build(); }
Example #2
Source File: AbstractModel.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
/** * Creates the PodDisruptionBudget * * @return The default PodDisruptionBudget */ protected PodDisruptionBudget createPodDisruptionBudget() { return new PodDisruptionBudgetBuilder() .withNewMetadata() .withName(name) .withLabels(getLabelsWithStrimziName(name, templatePodDisruptionBudgetLabels).toMap()) .withNamespace(namespace) .withAnnotations(templatePodDisruptionBudgetAnnotations) .withOwnerReferences(createOwnerReference()) .endMetadata() .withNewSpec() .withNewMaxUnavailable(templatePodDisruptionBudgetMaxUnavailable) .withSelector(new LabelSelectorBuilder().withMatchLabels(getSelectorLabels().toMap()).build()) .endSpec() .build(); }
Example #3
Source File: PodDisruptionBudgetTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { server.expect().withPath("/apis/policy/v1beta1/namespaces/test/poddisruptionbudgets/poddisruptionbudget1").andReturn(200, new PodDisruptionBudgetBuilder().build()).once(); server.expect().withPath("/apis/policy/v1beta1/namespaces/ns1/poddisruptionbudgets/poddisruptionbudget2").andReturn(200, new PodDisruptionBudgetBuilder().build()).once(); KubernetesClient client = server.getClient(); PodDisruptionBudget podDisruptionBudget = client.policy().podDisruptionBudget().withName("poddisruptionbudget1").get(); assertNotNull(podDisruptionBudget); podDisruptionBudget = client.policy().podDisruptionBudget().withName("poddisruptionbudget2").get(); assertNull(podDisruptionBudget); podDisruptionBudget = client.policy().podDisruptionBudget().inNamespace("ns1").withName("poddisruptionbudget2").get(); assertNotNull(podDisruptionBudget); }
Example #4
Source File: PodDisruptionBudgetTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testDelete() { server.expect().withPath("/apis/policy/v1beta1/namespaces/test/poddisruptionbudgets/poddisruptionbudget1").andReturn(200, new PodDisruptionBudgetBuilder() .withNewMetadata().withName("poddisruptionbudget1").withNamespace("test").endMetadata() .withNewSpec() .withMaxUnavailable(new IntOrString("1%")) .withNewSelector() .withMatchLabels(Collections.singletonMap("app", "zookeeper")) .endSelector() .endSpec() .build()).once(); KubernetesClient client = server.getClient(); Boolean deleted = client.policy().podDisruptionBudget().withName("poddisruptionbudget1").delete(); assertNotNull(deleted); assertTrue(deleted); }
Example #5
Source File: PodDisruptionBudgetOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected PodDisruptionBudget resource() { return new PodDisruptionBudgetBuilder() .withNewMetadata() .withName(RESOURCE_NAME) .withNamespace(NAMESPACE) .withLabels(singletonMap("foo", "bar")) .endMetadata() .withNewSpec() .withNewMaxUnavailable(1) .endSpec() .build(); }
Example #6
Source File: PodDisruptionBudgetTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testDeleteWithNamespaceMismatch() { Assertions.assertThrows(KubernetesClientException.class, () -> { PodDisruptionBudget podDisruptionBudget1 = new PodDisruptionBudgetBuilder().withNewMetadata().withName("podDisruptionBudget1").withNamespace("test").and().build(); KubernetesClient client = server.getClient(); Boolean deleted = client.policy().podDisruptionBudget().inNamespace("test1").delete(podDisruptionBudget1); assertFalse(deleted); }); }
Example #7
Source File: PodDisruptionBudgetTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testCreateWithNameMismatch() { Assertions.assertThrows(KubernetesClientException.class, () -> { PodDisruptionBudget podDisruptionBudget1 = new PodDisruptionBudgetBuilder().withNewMetadata().withName("podDisruptionBudget1").withNamespace("test").and().build(); KubernetesClient client = server.getClient(); client.policy().podDisruptionBudget().inNamespace("test1").withName("mypodDisruptionBudget1").create(podDisruptionBudget1); }); }
Example #8
Source File: PodDisruptionBudgetExample.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { final String namespace = "default"; PodDisruptionBudget podDisruptionBudget = new PodDisruptionBudgetBuilder() .withNewMetadata().withName("zk-pkb").endMetadata() .withNewSpec() .withMaxUnavailable(new IntOrString("1%")) .withNewSelector() .withMatchLabels(Collections.singletonMap("app", "zookeeper")) .endSelector() .endSpec() .build(); log("Current namespace is", namespace); client.policy().podDisruptionBudget().inNamespace(namespace).create(podDisruptionBudget); } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage()); } }
Example #9
Source File: PodIT.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void evict() throws InterruptedException { 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().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()) .waitUntilReady(30, TimeUnit.SECONDS); client.pods().inNamespace(currentNamespace).createOrReplace(pod2); client.pods().inNamespace(currentNamespace).withName(pod2.getMetadata().getName()) .waitUntilReady(30, TimeUnit.SECONDS); client.policy().podDisruptionBudget().inNamespace(currentNamespace).createOrReplace(pdb); assertTrue(client.pods().inNamespace(currentNamespace).withName(pod2.getMetadata().getName()).evict()); // cant evict because only one left assertFalse(client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).evict()); // ensure it really is still up assertTrue(Readiness.isReady(client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).fromServer().get())); // create another pod to satisfy PDB client.pods().inNamespace(currentNamespace).createOrReplace(pod3); client.pods().inNamespace(currentNamespace).withName(pod3.getMetadata().getName()) .waitUntilReady(30, TimeUnit.SECONDS); // can now evict assertTrue(client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).evict()); }