Search in sources :

Example 6 with PodAffinity

use of io.fabric8.kubernetes.api.model.PodAffinity in project strimzi by strimzi.

the class RackAwarenessST method testKafkaRackAwareness.

@ParallelNamespaceTest
void testKafkaRackAwareness(ExtensionContext extensionContext) {
    Assumptions.assumeFalse(Environment.isNamespaceRbacScope());
    TestStorage storage = storageMap.get(extensionContext);
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(storage.getClusterName(), 1, 1).editSpec().editKafka().withNewRack(TOPOLOGY_KEY).addToConfig("replica.selector.class", "org.apache.kafka.common.replica.RackAwareReplicaSelector").endKafka().endSpec().build());
    LOGGER.info("Kafka cluster deployed successfully");
    String ssName = KafkaResources.kafkaStatefulSetName(storage.getClusterName());
    String podName = PodUtils.getPodNameByPrefix(storage.getNamespaceName(), ssName);
    Pod pod = kubeClient().getPod(storage.getNamespaceName(), podName);
    // check that spec matches the actual pod configuration
    Affinity specAffinity = StUtils.getStatefulSetOrStrimziPodSetAffinity(storage.getNamespaceName(), KafkaResources.kafkaStatefulSetName(storage.getClusterName()));
    NodeSelectorRequirement specNodeRequirement = specAffinity.getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    NodeAffinity podAffinity = pod.getSpec().getAffinity().getNodeAffinity();
    NodeSelectorRequirement podNodeRequirement = podAffinity.getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    assertThat(podNodeRequirement, is(specNodeRequirement));
    assertThat(specNodeRequirement.getKey(), is(TOPOLOGY_KEY));
    assertThat(specNodeRequirement.getOperator(), is("Exists"));
    PodAffinityTerm specPodAntiAffinityTerm = specAffinity.getPodAntiAffinity().getPreferredDuringSchedulingIgnoredDuringExecution().get(0).getPodAffinityTerm();
    PodAffinityTerm podAntiAffinityTerm = pod.getSpec().getAffinity().getPodAntiAffinity().getPreferredDuringSchedulingIgnoredDuringExecution().get(0).getPodAffinityTerm();
    assertThat(podAntiAffinityTerm, is(specPodAntiAffinityTerm));
    assertThat(specPodAntiAffinityTerm.getTopologyKey(), is(TOPOLOGY_KEY));
    assertThat(specPodAntiAffinityTerm.getLabelSelector().getMatchLabels(), hasEntry("strimzi.io/cluster", storage.getClusterName()));
    assertThat(specPodAntiAffinityTerm.getLabelSelector().getMatchLabels(), hasEntry("strimzi.io/name", KafkaResources.kafkaStatefulSetName(storage.getClusterName())));
    // check Kafka rack awareness configuration
    String podNodeName = pod.getSpec().getNodeName();
    String hostname = podNodeName.contains(".") ? podNodeName.substring(0, podNodeName.indexOf(".")) : podNodeName;
    String rackIdOut = cmdKubeClient(storage.getNamespaceName()).execInPod(KafkaResources.kafkaPodName(storage.getClusterName(), 0), "/bin/bash", "-c", "cat /opt/kafka/init/rack.id").out().trim();
    String brokerRackOut = cmdKubeClient(storage.getNamespaceName()).execInPod(KafkaResources.kafkaPodName(storage.getClusterName(), 0), "/bin/bash", "-c", "cat /tmp/strimzi.properties | grep broker.rack").out().trim();
    assertThat(rackIdOut.trim(), is(hostname));
    assertThat(brokerRackOut.contains("broker.rack=" + hostname), is(true));
}
Also used : NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) PodAffinityTerm(io.fabric8.kubernetes.api.model.PodAffinityTerm) Pod(io.fabric8.kubernetes.api.model.Pod) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) TestStorage(io.strimzi.systemtest.storage.TestStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 7 with PodAffinity

use of io.fabric8.kubernetes.api.model.PodAffinity in project strimzi by strimzi.

the class RackAwarenessST method testMirrorMaker2RackAwareness.

@Tag(MIRROR_MAKER2)
@ParallelNamespaceTest
void testMirrorMaker2RackAwareness(ExtensionContext extensionContext) {
    Assumptions.assumeFalse(Environment.isNamespaceRbacScope());
    TestStorage storage = storageMap.get(extensionContext);
    String kafkaClusterSourceName = storage.getClusterName() + "-source";
    String kafkaClusterTargetName = storage.getClusterName() + "-target";
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterSourceName, 1, 1).build());
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterTargetName, 1, 1).build());
    resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(storage.getClusterName(), kafkaClusterTargetName, kafkaClusterSourceName, 1, false).editSpec().withNewRack(TOPOLOGY_KEY).endSpec().build());
    LOGGER.info("MirrorMaker2 cluster deployed successfully");
    String deployName = KafkaMirrorMaker2Resources.deploymentName(storage.getClusterName());
    String podName = PodUtils.getPodNameByPrefix(storage.getNamespaceName(), deployName);
    Pod pod = kubeClient().getPod(storage.getNamespaceName(), podName);
    // check that spec matches the actual pod configuration
    Affinity specAffinity = kubeClient().getDeployment(storage.getNamespaceName(), deployName).getSpec().getTemplate().getSpec().getAffinity();
    NodeSelectorRequirement specNodeRequirement = specAffinity.getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    NodeAffinity podAffinity = pod.getSpec().getAffinity().getNodeAffinity();
    NodeSelectorRequirement podNodeRequirement = podAffinity.getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    assertThat(podNodeRequirement, is(specNodeRequirement));
    assertThat(podNodeRequirement.getKey(), is(TOPOLOGY_KEY));
    assertThat(podNodeRequirement.getOperator(), is("Exists"));
    // check Kafka client rack awareness configuration
    String podNodeName = pod.getSpec().getNodeName();
    String hostname = podNodeName.contains(".") ? podNodeName.substring(0, podNodeName.indexOf(".")) : podNodeName;
    String commandOut = cmdKubeClient(storage.getNamespaceName()).execInPod(podName, "/bin/bash", "-c", "cat /tmp/strimzi-connect.properties | grep consumer.client.rack").out().trim();
    assertThat(commandOut.equals("consumer.client.rack=" + hostname), is(true));
}
Also used : NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) Pod(io.fabric8.kubernetes.api.model.Pod) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) TestStorage(io.strimzi.systemtest.storage.TestStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 8 with PodAffinity

use of io.fabric8.kubernetes.api.model.PodAffinity in project strimzi-kafka-operator by strimzi.

the class RackAwarenessST method testMirrorMaker2RackAwareness.

@Tag(MIRROR_MAKER2)
@ParallelNamespaceTest
void testMirrorMaker2RackAwareness(ExtensionContext extensionContext) {
    Assumptions.assumeFalse(Environment.isNamespaceRbacScope());
    TestStorage storage = storageMap.get(extensionContext);
    String kafkaClusterSourceName = storage.getClusterName() + "-source";
    String kafkaClusterTargetName = storage.getClusterName() + "-target";
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterSourceName, 1, 1).build());
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterTargetName, 1, 1).build());
    resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(storage.getClusterName(), kafkaClusterTargetName, kafkaClusterSourceName, 1, false).editSpec().withNewRack(TOPOLOGY_KEY).endSpec().build());
    LOGGER.info("MirrorMaker2 cluster deployed successfully");
    String deployName = KafkaMirrorMaker2Resources.deploymentName(storage.getClusterName());
    String podName = PodUtils.getPodNameByPrefix(storage.getNamespaceName(), deployName);
    Pod pod = kubeClient().getPod(storage.getNamespaceName(), podName);
    // check that spec matches the actual pod configuration
    Affinity specAffinity = kubeClient().getDeployment(storage.getNamespaceName(), deployName).getSpec().getTemplate().getSpec().getAffinity();
    NodeSelectorRequirement specNodeRequirement = specAffinity.getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    NodeAffinity podAffinity = pod.getSpec().getAffinity().getNodeAffinity();
    NodeSelectorRequirement podNodeRequirement = podAffinity.getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    assertThat(podNodeRequirement, is(specNodeRequirement));
    assertThat(podNodeRequirement.getKey(), is(TOPOLOGY_KEY));
    assertThat(podNodeRequirement.getOperator(), is("Exists"));
    // check Kafka client rack awareness configuration
    String podNodeName = pod.getSpec().getNodeName();
    String hostname = podNodeName.contains(".") ? podNodeName.substring(0, podNodeName.indexOf(".")) : podNodeName;
    String commandOut = cmdKubeClient(storage.getNamespaceName()).execInPod(podName, "/bin/bash", "-c", "cat /tmp/strimzi-connect.properties | grep consumer.client.rack").out().trim();
    assertThat(commandOut.equals("consumer.client.rack=" + hostname), is(true));
}
Also used : NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) Pod(io.fabric8.kubernetes.api.model.Pod) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeAffinity(io.fabric8.kubernetes.api.model.NodeAffinity) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) TestStorage(io.strimzi.systemtest.storage.TestStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Aggregations

Affinity (io.fabric8.kubernetes.api.model.Affinity)7 NodeAffinity (io.fabric8.kubernetes.api.model.NodeAffinity)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 NodeSelectorRequirement (io.fabric8.kubernetes.api.model.NodeSelectorRequirement)6 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)6 TestStorage (io.strimzi.systemtest.storage.TestStorage)6 Tag (org.junit.jupiter.api.Tag)4 PodAffinityTerm (io.fabric8.kubernetes.api.model.PodAffinityTerm)2 Rack (io.strimzi.api.kafka.model.Rack)2 DataTable (io.cucumber.datatable.DataTable)1 Given (io.cucumber.java.en.Given)1 Then (io.cucumber.java.en.Then)1 When (io.cucumber.java.en.When)1 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)1 DoneablePersistentVolume (io.fabric8.kubernetes.api.model.DoneablePersistentVolume)1 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)1 Node (io.fabric8.kubernetes.api.model.Node)1 NodeSelector (io.fabric8.kubernetes.api.model.NodeSelector)1 NodeSelectorTerm (io.fabric8.kubernetes.api.model.NodeSelectorTerm)1 PersistentVolumeFluent (io.fabric8.kubernetes.api.model.PersistentVolumeFluent)1