Search in sources :

Example 11 with PodDisruptionBudget

use of io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget in project strimzi by strimzi.

the class KafkaConnectClusterTest method testDefaultPodDisruptionBudget.

@ParallelTest
public void testDefaultPodDisruptionBudget() {
    KafkaConnect resource = new KafkaConnectBuilder(this.resource).build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    PodDisruptionBudget pdb = kc.generatePodDisruptionBudget();
    assertThat(pdb.getSpec().getMaxUnavailable(), is(new IntOrString(1)));
    io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget pdbV1Beta1 = kc.generatePodDisruptionBudgetV1Beta1();
    assertThat(pdbV1Beta1.getSpec().getMaxUnavailable(), is(new IntOrString(1)));
}
Also used : KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 12 with PodDisruptionBudget

use of io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget in project strimzi by strimzi.

the class KafkaMirrorMakerClusterTest method testDefaultPodDisruptionBudget.

@ParallelTest
public void testDefaultPodDisruptionBudget() {
    KafkaMirrorMaker resource = new KafkaMirrorMakerBuilder(this.resource).build();
    KafkaMirrorMakerCluster mmc = KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    PodDisruptionBudget pdb = mmc.generatePodDisruptionBudget();
    assertThat(pdb.getSpec().getMaxUnavailable(), is(new IntOrString(1)));
}
Also used : KafkaMirrorMakerBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerBuilder) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with PodDisruptionBudget

use of io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget in project strimzi by strimzi.

the class KafkaMirrorMakerClusterTest method testTemplate.

@ParallelTest
public void testTemplate() {
    Map<String, String> depLabels = TestUtils.map("l1", "v1", "l2", "v2", Labels.KUBERNETES_PART_OF_LABEL, "custom-part", Labels.KUBERNETES_MANAGED_BY_LABEL, "custom-managed-by");
    Map<String, String> expectedDepLabels = new HashMap<>(depLabels);
    expectedDepLabels.remove(Labels.KUBERNETES_MANAGED_BY_LABEL);
    Map<String, String> depAnots = TestUtils.map("a1", "v1", "a2", "v2");
    Map<String, String> podLabels = TestUtils.map("l3", "v3", "l4", "v4");
    Map<String, String> podAnots = TestUtils.map("a3", "v3", "a4", "v4");
    Map<String, String> pdbLabels = TestUtils.map("l5", "v5", "l6", "v6");
    Map<String, String> pdbAnots = TestUtils.map("a5", "v5", "a6", "v6");
    Map<String, String> saLabels = TestUtils.map("l7", "v7", "l8", "v8");
    Map<String, String> saAnots = TestUtils.map("a7", "v7", "a8", "v8");
    HostAlias hostAlias1 = new HostAliasBuilder().withHostnames("my-host-1", "my-host-2").withIp("192.168.1.86").build();
    HostAlias hostAlias2 = new HostAliasBuilder().withHostnames("my-host-3").withIp("192.168.1.87").build();
    KafkaMirrorMaker resource = new KafkaMirrorMakerBuilder(this.resource).editSpec().withNewTemplate().withNewDeployment().withNewMetadata().withLabels(depLabels).withAnnotations(depAnots).endMetadata().withDeploymentStrategy(DeploymentStrategy.RECREATE).endDeployment().withNewPod().withNewMetadata().withLabels(podLabels).withAnnotations(podAnots).endMetadata().withPriorityClassName("top-priority").withSchedulerName("my-scheduler").withHostAliases(hostAlias1, hostAlias2).withEnableServiceLinks(false).withTmpDirSizeLimit("10Mi").endPod().withNewPodDisruptionBudget().withNewMetadata().withLabels(pdbLabels).withAnnotations(pdbAnots).endMetadata().endPodDisruptionBudget().withNewServiceAccount().withNewMetadata().withLabels(saLabels).withAnnotations(saAnots).endMetadata().endServiceAccount().endTemplate().endSpec().build();
    KafkaMirrorMakerCluster mmc = KafkaMirrorMakerCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    // Check Deployment
    Deployment dep = mmc.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getMetadata().getLabels().entrySet().containsAll(expectedDepLabels.entrySet()), is(true));
    assertThat(dep.getMetadata().getAnnotations().entrySet().containsAll(depAnots.entrySet()), is(true));
    assertThat(dep.getSpec().getTemplate().getSpec().getPriorityClassName(), is("top-priority"));
    assertThat(dep.getSpec().getStrategy().getType(), is("Recreate"));
    assertThat(dep.getSpec().getStrategy().getRollingUpdate(), is(nullValue()));
    // Check Pods
    assertThat(dep.getSpec().getTemplate().getMetadata().getLabels().entrySet().containsAll(podLabels.entrySet()), is(true));
    assertThat(dep.getSpec().getTemplate().getMetadata().getAnnotations().entrySet().containsAll(podAnots.entrySet()), is(true));
    assertThat(dep.getSpec().getTemplate().getSpec().getSchedulerName(), is("my-scheduler"));
    assertThat(dep.getSpec().getTemplate().getSpec().getHostAliases(), containsInAnyOrder(hostAlias1, hostAlias2));
    assertThat(dep.getSpec().getTemplate().getSpec().getEnableServiceLinks(), is(false));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().get().getEmptyDir().getSizeLimit(), is(new Quantity("10Mi")));
    // Check PodDisruptionBudget
    PodDisruptionBudget pdb = mmc.generatePodDisruptionBudget();
    assertThat(pdb.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true));
    assertThat(pdb.getMetadata().getAnnotations().entrySet().containsAll(pdbAnots.entrySet()), is(true));
    // Check PodDisruptionBudgetV1Beta1
    io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget pdbV1Beta1 = mmc.generatePodDisruptionBudgetV1Beta1();
    assertThat(pdbV1Beta1.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true));
    assertThat(pdbV1Beta1.getMetadata().getAnnotations().entrySet().containsAll(pdbAnots.entrySet()), is(true));
    // Check Service Account
    ServiceAccount sa = mmc.generateServiceAccount();
    assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
    assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnots.entrySet()), is(true));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaMirrorMakerProducerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpecBuilder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) KafkaMirrorMakerResources(io.strimzi.api.kafka.model.KafkaMirrorMakerResources) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) ClientConfig(io.strimzi.kafka.oauth.client.ClientConfig) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Map(java.util.Map) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) ParallelTest(io.strimzi.test.annotations.ParallelTest) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) KafkaClientAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuthBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) Labels(io.strimzi.operator.common.model.Labels) KafkaMirrorMakerConsumerSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpecBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) LINE_SEPARATOR(io.strimzi.test.TestUtils.LINE_SEPARATOR) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ContainerTemplate(io.strimzi.api.kafka.model.template.ContainerTemplate) Container(io.fabric8.kubernetes.api.model.Container) KafkaMirrorMakerConsumerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerConsumerSpec) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) KafkaClientAuthenticationTlsBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTlsBuilder) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) ArrayList(java.util.ArrayList) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) JmxPrometheusExporterMetrics(io.strimzi.api.kafka.model.JmxPrometheusExporterMetrics) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) DeploymentStrategy(io.strimzi.api.kafka.model.template.DeploymentStrategy) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) KafkaMirrorMakerBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerBuilder) KafkaMirrorMakerProducerSpec(io.strimzi.api.kafka.model.KafkaMirrorMakerProducerSpec) TestUtils(io.strimzi.test.TestUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Probe(io.fabric8.kubernetes.api.model.Probe) Collections.emptyMap(java.util.Collections.emptyMap) ServerConfig(io.strimzi.kafka.oauth.server.ServerConfig) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) KafkaMirrorMakerBuilder(io.strimzi.api.kafka.model.KafkaMirrorMakerBuilder) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) HashMap(java.util.HashMap) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Quantity(io.fabric8.kubernetes.api.model.Quantity) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) KafkaMirrorMaker(io.strimzi.api.kafka.model.KafkaMirrorMaker) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 14 with PodDisruptionBudget

use of io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget in project strimzi by strimzi.

the class KafkaPodSetTest method testCustomizedPodDisruptionBudget.

@ParallelTest
public void testCustomizedPodDisruptionBudget() {
    Map<String, String> pdbLabels = TestUtils.map("l1", "v1", "l2", "v2");
    Map<String, String> pdbAnnos = TestUtils.map("a1", "v1", "a2", "v2");
    Kafka kafka = new KafkaBuilder(KAFKA).editSpec().editKafka().withNewTemplate().withNewPodDisruptionBudget().withNewMetadata().withAnnotations(pdbAnnos).withLabels(pdbLabels).endMetadata().withMaxUnavailable(2).endPodDisruptionBudget().endTemplate().endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    PodDisruptionBudget pdb = kc.generateCustomControllerPodDisruptionBudget();
    assertThat(pdb.getMetadata().getLabels().entrySet().containsAll(pdbLabels.entrySet()), is(true));
    assertThat(pdb.getMetadata().getAnnotations().entrySet().containsAll(pdbAnnos.entrySet()), is(true));
    assertThat(pdb.getSpec().getMaxUnavailable(), is(nullValue()));
    assertThat(pdb.getSpec().getMinAvailable().getIntVal(), is(1));
    assertThat(pdb.getSpec().getSelector().getMatchLabels(), is(kc.getSelectorLabels().toMap()));
}
Also used : PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 15 with PodDisruptionBudget

use of io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget in project strimzi by strimzi.

the class ZookeeperClusterTest method testDefaultPodDisruptionBudget.

@ParallelTest
public void testDefaultPodDisruptionBudget() {
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, emptyMap())).build();
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
    PodDisruptionBudget pdb = zc.generatePodDisruptionBudget();
    assertThat(pdb.getSpec().getMaxUnavailable(), is(new IntOrString(1)));
}
Also used : PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)104 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)64 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)64 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)64 Reconciliation (io.strimzi.operator.common.Reconciliation)64 TestUtils (io.strimzi.test.TestUtils)64 Collections (java.util.Collections)64 HashMap (java.util.HashMap)64 List (java.util.List)64 CoreMatchers.is (org.hamcrest.CoreMatchers.is)64 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)64 Test (org.junit.jupiter.api.Test)64 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)62 Labels (io.strimzi.operator.common.model.Labels)60 Map (java.util.Map)60 Service (io.fabric8.kubernetes.api.model.Service)58 KubernetesVersion (io.strimzi.operator.KubernetesVersion)56 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)56 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)56 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)56