use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testPodDisruptionBudget.
@ParallelTest
public void testPodDisruptionBudget() {
int maxUnavailable = 2;
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withNewTemplate().withNewPodDisruptionBudget().withMaxUnavailable(maxUnavailable).endPodDisruptionBudget().endTemplate().build();
Kafka resource = createKafka(cruiseControlSpec);
CruiseControl cc = createCruiseControl(resource);
Deployment dep = cc.generateDeployment(true, null, null, null);
List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers();
Container ccContainer = containers.stream().filter(container -> ccImage.equals(container.getImage())).findFirst().orElseThrow();
PodDisruptionBudget pdb = cc.generatePodDisruptionBudget();
assertThat(pdb.getSpec().getMaxUnavailable(), is(new IntOrString(maxUnavailable)));
io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget pdbV1Beta1 = cc.generatePodDisruptionBudgetV1Beta1();
assertThat(pdbV1Beta1.getSpec().getMaxUnavailable(), is(new IntOrString(maxUnavailable)));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testTemplate.
@ParallelTest
public void testTemplate() {
Map<String, String> depLabels = TestUtils.map("l1", "v1", "l2", "v2");
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> svcLabels = TestUtils.map("l5", "v5", "l6", "v6");
Map<String, String> svcAnots = 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");
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());
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();
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withNewTemplate().withNewDeployment().withNewMetadata().withLabels(depLabels).withAnnotations(depAnots).endMetadata().endDeployment().withNewPod().withNewMetadata().withLabels(podLabels).withAnnotations(podAnots).endMetadata().withPriorityClassName("top-priority").withSchedulerName("my-scheduler").withHostAliases(hostAlias1, hostAlias2).withAffinity(affinity).withTolerations(tolerations).endPod().withNewApiService().withNewMetadata().withLabels(svcLabels).withAnnotations(svcAnots).endMetadata().withIpFamilyPolicy(IpFamilyPolicy.PREFER_DUAL_STACK).withIpFamilies(IpFamily.IPV6, IpFamily.IPV4).endApiService().withNewServiceAccount().withNewMetadata().withLabels(saLabels).withAnnotations(saAnots).endMetadata().endServiceAccount().endTemplate().build();
Kafka resource = createKafka(cruiseControlSpec);
CruiseControl cc = createCruiseControl(resource);
// Check Deployment
Deployment dep = cc.generateDeployment(true, depAnots, null, null);
depLabels.putAll(expectedLabels());
assertThat(dep.getMetadata().getLabels(), is(depLabels));
assertThat(dep.getMetadata().getAnnotations(), is(depAnots));
// Check Pods
podLabels.putAll(expectedLabels());
assertThat(dep.getSpec().getTemplate().getMetadata().getLabels(), is(podLabels));
assertThat(dep.getSpec().getTemplate().getMetadata().getAnnotations(), is(podAnots));
assertThat(dep.getSpec().getTemplate().getSpec().getPriorityClassName(), is("top-priority"));
assertThat(dep.getSpec().getTemplate().getSpec().getSchedulerName(), is("my-scheduler"));
assertThat(dep.getSpec().getTemplate().getSpec().getAffinity(), is(affinity));
assertThat(dep.getSpec().getTemplate().getSpec().getTolerations(), is(tolerations));
assertThat(dep.getSpec().getTemplate().getSpec().getHostAliases(), containsInAnyOrder(hostAlias1, hostAlias2));
// Check Service
svcLabels.putAll(expectedLabels());
Service svc = cc.generateService();
assertThat(svc.getMetadata().getLabels(), is(svcLabels));
assertThat(svc.getMetadata().getAnnotations(), is(svcAnots));
assertThat(svc.getSpec().getIpFamilyPolicy(), is("PreferDualStack"));
assertThat(svc.getSpec().getIpFamilies(), contains("IPv6", "IPv4"));
// Check Service Account
ServiceAccount sa = cc.generateServiceAccount();
assertThat(sa.getMetadata().getLabels().entrySet().containsAll(saLabels.entrySet()), is(true));
assertThat(sa.getMetadata().getAnnotations().entrySet().containsAll(saAnots.entrySet()), is(true));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControlConfigurationST method testConfigurationDiskChangeDoNotTriggersRollingUpdateOfKafkaPods.
@ParallelNamespaceTest
void testConfigurationDiskChangeDoNotTriggersRollingUpdateOfKafkaPods(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName));
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaWithCruiseControl(clusterName, 3, 3).build());
Map<String, String> kafkaSnapShot = PodUtils.podSnapshot(namespaceName, kafkaSelector);
Map<String, String> cruiseControlSnapShot = DeploymentUtils.depSnapshot(namespaceName, CruiseControlResources.deploymentName(clusterName));
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> {
LOGGER.info("Changing the broker capacity of the cruise control");
CruiseControlSpec cruiseControl = new CruiseControlSpecBuilder().withNewBrokerCapacity().withOutboundNetwork("20KB/s").endBrokerCapacity().build();
kafka.getSpec().setCruiseControl(cruiseControl);
}, namespaceName);
LOGGER.info("Verifying that CC pod is rolling, because of change size of disk");
DeploymentUtils.waitTillDepHasRolled(namespaceName, CruiseControlResources.deploymentName(clusterName), 1, cruiseControlSnapShot);
LOGGER.info("Verifying that Kafka pods did not roll");
RollingUpdateUtils.waitForNoRollingUpdate(namespaceName, kafkaSelector, kafkaSnapShot);
LOGGER.info("Verifying new configuration in the Kafka CR");
assertThat(KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getCruiseControl().getBrokerCapacity().getOutboundNetwork(), is("20KB/s"));
CruiseControlUtils.verifyThatCruiseControlTopicsArePresent(namespaceName);
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControlConfigurationST method testDeployAndUnDeployCruiseControl.
@ParallelNamespaceTest
void testDeployAndUnDeployCruiseControl(ExtensionContext extensionContext) throws IOException {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
final LabelSelector kafkaSelector = KafkaResource.getLabelSelector(clusterName, KafkaResources.kafkaStatefulSetName(clusterName));
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaWithCruiseControl(clusterName, 3, 3).build());
Map<String, String> kafkaPods = PodUtils.podSnapshot(namespaceName, kafkaSelector);
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> {
LOGGER.info("Removing Cruise Control to the classic Kafka.");
kafka.getSpec().setCruiseControl(null);
}, namespaceName);
kafkaPods = RollingUpdateUtils.waitTillComponentHasRolled(namespaceName, kafkaSelector, 3, kafkaPods);
LOGGER.info("Verifying that in {} is not present in the Kafka cluster", Constants.CRUISE_CONTROL_NAME);
assertThat(KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).get().getSpec().getCruiseControl(), nullValue());
LOGGER.info("Verifying that {} pod is not present", clusterName + "-cruise-control-");
PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, clusterName + "-cruise-control-", 0);
LOGGER.info("Verifying that in Kafka config map there is no configuration to cruise control metric reporter");
assertThrows(WaitException.class, () -> CruiseControlUtils.verifyCruiseControlMetricReporterConfigurationInKafkaConfigMapIsPresent(CruiseControlUtils.getKafkaCruiseControlMetricsReporterConfiguration(namespaceName, clusterName)));
LOGGER.info("Cruise Control topics will not be deleted and will stay in the Kafka cluster");
CruiseControlUtils.verifyThatCruiseControlTopicsArePresent(namespaceName);
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> {
LOGGER.info("Adding Cruise Control to the classic Kafka.");
kafka.getSpec().setCruiseControl(new CruiseControlSpec());
}, namespaceName);
RollingUpdateUtils.waitTillComponentHasRolled(namespaceName, kafkaSelector, 3, kafkaPods);
LOGGER.info("Verifying that in Kafka config map there is configuration to cruise control metric reporter");
CruiseControlUtils.verifyCruiseControlMetricReporterConfigurationInKafkaConfigMapIsPresent(CruiseControlUtils.getKafkaCruiseControlMetricsReporterConfiguration(namespaceName, clusterName));
LOGGER.info("Verifying that {} topics are created after CC is instantiated.", Constants.CRUISE_CONTROL_NAME);
CruiseControlUtils.verifyThatCruiseControlTopicsArePresent(namespaceName);
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class KafkaBrokerConfigurationBuilderTest method testCruiseControl.
@ParallelTest
public void testCruiseControl() {
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().build();
String configuration = new KafkaBrokerConfigurationBuilder(Reconciliation.DUMMY_RECONCILIATION).withCruiseControl("my-cluster", cruiseControlSpec, "1", "1", "1").build();
assertThat(configuration, containsString(CruiseControlConfigurationParameters.METRICS_TOPIC_NAME + "=strimzi.cruisecontrol.metrics\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_ENDPOINT_ID_ALGO + "=HTTPS\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_BOOTSTRAP_SERVERS + "=my-cluster-kafka-brokers:9091\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SECURITY_PROTOCOL + "=SSL\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_KEYSTORE_TYPE + "=PKCS12\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_KEYSTORE_LOCATION + "=/tmp/kafka/cluster.keystore.p12\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_KEYSTORE_PASSWORD + "=${CERTS_STORE_PASSWORD}\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_TRUSTSTORE_TYPE + "=PKCS12\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_TRUSTSTORE_LOCATION + "=/tmp/kafka/cluster.truststore.p12\n" + CruiseControlConfigurationParameters.METRICS_REPORTER_SSL_TRUSTSTORE_PASSWORD + "=${CERTS_STORE_PASSWORD}\n" + CruiseControlConfigurationParameters.METRICS_TOPIC_AUTO_CREATE + "=true\n" + CruiseControlConfigurationParameters.METRICS_TOPIC_NUM_PARTITIONS + "=1\n" + CruiseControlConfigurationParameters.METRICS_TOPIC_REPLICATION_FACTOR + "=1\n" + CruiseControlConfigurationParameters.METRICS_TOPIC_MIN_ISR + "=1"));
}
Aggregations