Search in sources :

Example 1 with PodTemplate

use of io.strimzi.api.kafka.model.template.PodTemplate in project strimzi by strimzi.

the class ModelUtilsTest method testEmptyTolerations.

@ParallelTest
public void testEmptyTolerations() {
    Toleration t1 = new TolerationBuilder().withValue("").withEffect("NoExecute").build();
    Toleration t2 = new TolerationBuilder().withValue(null).withEffect("NoExecute").build();
    PodTemplate pt1 = new PodTemplate();
    pt1.setTolerations(singletonList(t1));
    PodTemplate pt2 = new PodTemplate();
    pt2.setTolerations(singletonList(t2));
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().withNewSpec().withNewKafka().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withPort(9092).withName("plain").withTls(false).build()).endKafka().endSpec().build();
    KafkaCluster model1 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
    ModelUtils.parsePodTemplate(model1, pt1);
    KafkaCluster model2 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
    ModelUtils.parsePodTemplate(model2, pt2);
    assertThat(model1.getTolerations(), is(model2.getTolerations()));
}
Also used : TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Toleration(io.fabric8.kubernetes.api.model.Toleration) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 2 with PodTemplate

use of io.strimzi.api.kafka.model.template.PodTemplate in project strimzi by strimzi.

the class KafkaRollerIsolatedST method testKafkaPodPendingDueToRack.

@ParallelNamespaceTest
void testKafkaPodPendingDueToRack(ExtensionContext extensionContext) {
    // Testing this scenario
    // 1. deploy Kafka with wrong pod template (looking for nonexistent node) kafka pods should not exist
    // 2. wait for Kafka not ready, kafka pods should be in the pending state
    // 3. fix the Kafka CR, kafka pods should be in the pending state
    // 4. wait for Kafka ready, kafka pods should NOT be in the pending state
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    NodeSelectorRequirement nsr = new NodeSelectorRequirementBuilder().withKey("dedicated_test").withOperator("In").withValues("Kafka").build();
    NodeSelectorTerm nst = new NodeSelectorTermBuilder().withMatchExpressions(nsr).build();
    Affinity affinity = new AffinityBuilder().withNewNodeAffinity().withNewRequiredDuringSchedulingIgnoredDuringExecution().withNodeSelectorTerms(nst).endRequiredDuringSchedulingIgnoredDuringExecution().endNodeAffinity().build();
    PodTemplate pt = new PodTemplate();
    pt.setAffinity(affinity);
    KafkaClusterTemplate kct = new KafkaClusterTemplateBuilder().withPod(pt).build();
    resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaEphemeral(clusterName, 3, 3).editSpec().editKafka().withTemplate(kct).endKafka().endSpec().build());
    // pods are stable in the Pending state
    PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, KafkaResources.kafkaStatefulSetName(clusterName), 3);
    LOGGER.info("Removing requirement for the affinity");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().getTemplate().getPod().setAffinity(null), namespaceName);
    // kafka should get back ready in some reasonable time frame
    KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
    KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
    KafkaUtils.waitForKafkaDeletion(namespaceName, clusterName);
}
Also used : NodeSelectorRequirementBuilder(io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) Affinity(io.fabric8.kubernetes.api.model.Affinity) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) NodeSelectorTerm(io.fabric8.kubernetes.api.model.NodeSelectorTerm) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 3 with PodTemplate

use of io.strimzi.api.kafka.model.template.PodTemplate in project debezium by debezium.

the class OcpKafkaDeployer method configurePullSecret.

public void configurePullSecret(KafkaBuilder builder) {
    PodTemplate podTemplate = new PodTemplateBuilder().addNewImagePullSecret(pullSecretName).build();
    builder.editSpec().editKafka().withNewTemplate().withPod(podTemplate).endTemplate().endKafka().editZookeeper().withNewTemplate().withPod(podTemplate).endTemplate().endZookeeper().editEntityOperator().withNewTemplate().withPod(podTemplate).endTemplate().endEntityOperator().endSpec();
}
Also used : PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate)

Example 4 with PodTemplate

use of io.strimzi.api.kafka.model.template.PodTemplate in project strimzi-kafka-operator by strimzi.

the class ModelUtilsTest method testEmptyTolerations.

@ParallelTest
public void testEmptyTolerations() {
    Toleration t1 = new TolerationBuilder().withValue("").withEffect("NoExecute").build();
    Toleration t2 = new TolerationBuilder().withValue(null).withEffect("NoExecute").build();
    PodTemplate pt1 = new PodTemplate();
    pt1.setTolerations(singletonList(t1));
    PodTemplate pt2 = new PodTemplate();
    pt2.setTolerations(singletonList(t2));
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().withNewSpec().withNewKafka().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withPort(9092).withName("plain").withTls(false).build()).endKafka().endSpec().build();
    KafkaCluster model1 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
    ModelUtils.parsePodTemplate(model1, pt1);
    KafkaCluster model2 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
    ModelUtils.parsePodTemplate(model2, pt2);
    assertThat(model1.getTolerations(), is(model2.getTolerations()));
}
Also used : TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Toleration(io.fabric8.kubernetes.api.model.Toleration) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 5 with PodTemplate

use of io.strimzi.api.kafka.model.template.PodTemplate in project strimzi by strimzi.

the class ModelUtilsTest method testParsePodTemplate.

@Test
public void testParsePodTemplate() {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().build();
    LocalObjectReference secret1 = new LocalObjectReference("some-pull-secret");
    LocalObjectReference secret2 = new LocalObjectReference("some-other-pull-secret");
    Affinity affinity = new AffinityBuilder().withNewNodeAffinity().withNewRequiredDuringSchedulingIgnoredDuringExecution().withNodeSelectorTerms(new NodeSelectorTermBuilder().addNewMatchExpression().withKey("key1").withOperator("In").withValues("value1", "value2").endMatchExpression().build()).endRequiredDuringSchedulingIgnoredDuringExecution().endNodeAffinity().build();
    List<Toleration> tolerations = singletonList(new TolerationBuilder().withEffect("NoExecute").withKey("key1").withOperator("Equal").withValue("value1").build());
    PodTemplate template = new PodTemplateBuilder().withNewMetadata().withAnnotations(Collections.singletonMap("annoKey", "annoValue")).withLabels(Collections.singletonMap("labelKey", "labelValue")).endMetadata().withSecurityContext(new PodSecurityContextBuilder().withFsGroup(123L).withRunAsGroup(456L).withRunAsUser(789L).build()).withImagePullSecrets(secret1, secret2).withTerminationGracePeriodSeconds(123).withAffinity(affinity).withTolerations(tolerations).build();
    Model model = new Model(Reconciliation.DUMMY_RECONCILIATION, kafka);
    ModelUtils.parsePodTemplate(model, template);
    assertThat(model.templatePodLabels, is(Collections.singletonMap("labelKey", "labelValue")));
    assertThat(model.templatePodAnnotations, is(Collections.singletonMap("annoKey", "annoValue")));
    assertThat(model.templateTerminationGracePeriodSeconds, is(123));
    assertThat(model.templateImagePullSecrets.size(), is(2));
    assertThat(model.templateImagePullSecrets.contains(secret1), is(true));
    assertThat(model.templateImagePullSecrets.contains(secret2), is(true));
    assertThat(model.templateSecurityContext, is(notNullValue()));
    assertThat(model.templateSecurityContext.getFsGroup(), is(Long.valueOf(123)));
    assertThat(model.templateSecurityContext.getRunAsGroup(), is(Long.valueOf(456)));
    assertThat(model.templateSecurityContext.getRunAsUser(), is(Long.valueOf(789)));
    assertThat(model.getUserAffinity(), is(affinity));
    assertThat(model.getTolerations(), is(tolerations));
}
Also used : PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Toleration(io.fabric8.kubernetes.api.model.Toleration) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelTest(io.strimzi.test.annotations.ParallelTest) Test(org.junit.jupiter.api.Test)

Aggregations

PodTemplate (io.strimzi.api.kafka.model.template.PodTemplate)7 Affinity (io.fabric8.kubernetes.api.model.Affinity)4 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)4 NodeSelectorTermBuilder (io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder)4 Toleration (io.fabric8.kubernetes.api.model.Toleration)4 TolerationBuilder (io.fabric8.kubernetes.api.model.TolerationBuilder)4 Kafka (io.strimzi.api.kafka.model.Kafka)4 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)4 ParallelTest (io.strimzi.test.annotations.ParallelTest)4 PodTemplateBuilder (io.strimzi.api.kafka.model.template.PodTemplateBuilder)3 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)2 NodeSelectorRequirement (io.fabric8.kubernetes.api.model.NodeSelectorRequirement)2 NodeSelectorRequirementBuilder (io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder)2 NodeSelectorTerm (io.fabric8.kubernetes.api.model.NodeSelectorTerm)2 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 KafkaClusterTemplate (io.strimzi.api.kafka.model.template.KafkaClusterTemplate)2 KafkaClusterTemplateBuilder (io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2 Test (org.junit.jupiter.api.Test)2