use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator 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-kafka-operator by strimzi.
the class CruiseControlTest method testResources.
@ParallelTest
public void testResources() {
Map<String, Quantity> requests = new HashMap<>(2);
requests.put("cpu", new Quantity("250m"));
requests.put("memory", new Quantity("512Mi"));
Map<String, Quantity> limits = new HashMap<>(2);
limits.put("cpu", new Quantity("500m"));
limits.put("memory", new Quantity("1024Mi"));
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build()).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();
assertThat(ccContainer.getResources().getLimits(), is(limits));
assertThat(ccContainer.getResources().getRequests(), is(requests));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator 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-kafka-operator by strimzi.
the class CruiseControlTest method testSecurityContext.
@ParallelTest
public void testSecurityContext() {
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withConfig(ccConfig).withNewTemplate().withNewPod().withSecurityContext(new PodSecurityContextBuilder().withFsGroup(123L).withRunAsGroup(456L).withRunAsUser(789L).build()).endPod().endTemplate().build();
Kafka resource = createKafka(cruiseControlSpec);
CruiseControl cc = createCruiseControl(resource);
Deployment dep = cc.generateDeployment(true, null, null, null);
assertThat(dep.getSpec().getTemplate().getSpec().getSecurityContext(), is(notNullValue()));
assertThat(dep.getSpec().getTemplate().getSpec().getSecurityContext().getFsGroup(), is(Long.valueOf(123)));
assertThat(dep.getSpec().getTemplate().getSpec().getSecurityContext().getRunAsGroup(), is(Long.valueOf(456)));
assertThat(dep.getSpec().getTemplate().getSpec().getSecurityContext().getRunAsUser(), is(Long.valueOf(789)));
}
use of io.strimzi.api.kafka.model.CruiseControlSpec in project strimzi-kafka-operator by strimzi.
the class CruiseControlTest method testApiSecurity.
public void testApiSecurity(Boolean apiAuthEnabled, Boolean apiSslEnabled) {
String e1Key = CruiseControl.ENV_VAR_API_AUTH_ENABLED;
String e1Value = apiAuthEnabled.toString();
EnvVar e1 = new EnvVar(e1Key, e1Value, null);
String e2Key = CruiseControl.ENV_VAR_API_SSL_ENABLED;
String e2Value = apiSslEnabled.toString();
EnvVar e2 = new EnvVar(e2Key, e2Value, null);
Map<String, Object> config = ccConfig;
config.put(CruiseControlConfigurationParameters.CRUISE_CONTROL_WEBSERVER_SECURITY_ENABLE.getValue(), apiAuthEnabled);
config.put(CruiseControlConfigurationParameters.CRUISE_CONTROL_WEBSERVER_SSL_ENABLE.getValue(), apiSslEnabled);
CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withConfig(config).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();
// checks on the main Cruise Control container
Container ccContainer = containers.stream().filter(container -> ccImage.equals(container.getImage())).findFirst().get();
List<EnvVar> envVarList = ccContainer.getEnv();
assertThat(envVarList.contains(e1), is(true));
assertThat(envVarList.contains(e2), is(true));
}
Aggregations