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));
}
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));
}
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));
}
Aggregations