use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi by strimzi.
the class CruiseControlTest method testJvmOptions.
@ParallelTest
public void testJvmOptions() {
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withNewJvmOptions().withXms("128m").withXmx("256m").withXx(Map.of("InitiatingHeapOccupancyPercent", "36")).withJavaSystemProperties(new SystemPropertyBuilder().withName("myProperty").withValue("myValue").build(), new SystemPropertyBuilder().withName("myProperty2").withValue("myValue2").build()).endJvmOptions().build();
Kafka resource = createKafka(cruiseControlSpec);
CruiseControl cc = CruiseControl.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS, kafkaStorage);
EnvVar systemProps = cc.getEnvVars().stream().filter(var -> AbstractModel.ENV_VAR_STRIMZI_JAVA_SYSTEM_PROPERTIES.equals(var.getName())).findFirst().orElse(null);
assertThat(systemProps, is(notNullValue()));
assertThat(systemProps.getValue(), containsString("-DmyProperty=myValue"));
assertThat(systemProps.getValue(), containsString("-DmyProperty2=myValue2"));
EnvVar heapOpts = cc.getEnvVars().stream().filter(var -> AbstractModel.ENV_VAR_KAFKA_HEAP_OPTS.equals(var.getName())).findFirst().orElse(null);
assertThat(heapOpts, is(notNullValue()));
assertThat(heapOpts.getValue(), containsString("-Xms128m"));
assertThat(heapOpts.getValue(), containsString("-Xmx256m"));
EnvVar perfOptions = cc.getEnvVars().stream().filter(var -> AbstractModel.ENV_VAR_KAFKA_JVM_PERFORMANCE_OPTS.equals(var.getName())).findFirst().orElse(null);
assertThat(perfOptions, is(notNullValue()));
assertThat(perfOptions.getValue(), containsString("-XX:InitiatingHeapOccupancyPercent=36"));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi by strimzi.
the class CruiseControlTest method testMetricsParsingFromConfigMap.
@ParallelTest
public void testMetricsParsingFromConfigMap() {
MetricsConfig metrics = new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-metrics-configuration").withKey("config.yaml").build()).endValueFrom().build();
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withMetricsConfig(metrics).build();
Kafka kafkaAssembly = createKafka(cruiseControlSpec);
CruiseControl cc = createCruiseControl(kafkaAssembly);
assertThat(cc.isMetricsEnabled(), is(true));
assertThat(cc.getMetricsConfigInCm(), is(metrics));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi by strimzi.
the class CruiseControlTest method testCruiseControlContainerSecurityContext.
@ParallelTest
public void testCruiseControlContainerSecurityContext() {
SecurityContext securityContext = new SecurityContextBuilder().withPrivileged(false).withReadOnlyRootFilesystem(false).withAllowPrivilegeEscalation(false).withRunAsNonRoot(true).withNewCapabilities().addNewDrop("ALL").endCapabilities().build();
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withConfig(ccConfig).withNewTemplate().withNewCruiseControlContainer().withSecurityContext(securityContext).endCruiseControlContainer().endTemplate().build();
Kafka resource = createKafka(cruiseControlSpec);
CruiseControl cc = createCruiseControl(resource);
Deployment dep = cc.generateDeployment(true, null, null, null);
assertThat(dep.getSpec().getTemplate().getSpec().getContainers(), hasItem(allOf(hasProperty("name", equalTo(CruiseControl.CRUISE_CONTROL_CONTAINER_NAME)), hasProperty("securityContext", equalTo(securityContext)))));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi 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 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)));
}
Aggregations