Search in sources :

Example 11 with CruiseControlSpec

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)))));
}
Also used : SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 12 with CruiseControlSpec

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));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) HashMap(java.util.HashMap) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) Quantity(io.fabric8.kubernetes.api.model.Quantity) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with CruiseControlSpec

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));
}
Also used : CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) MetricsConfig(io.strimzi.api.kafka.model.MetricsConfig) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 14 with CruiseControlSpec

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)));
}
Also used : PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 15 with CruiseControlSpec

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));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) Kafka(io.strimzi.api.kafka.model.Kafka) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Aggregations

CruiseControlSpec (io.strimzi.api.kafka.model.CruiseControlSpec)38 CruiseControlSpecBuilder (io.strimzi.api.kafka.model.CruiseControlSpecBuilder)34 Kafka (io.strimzi.api.kafka.model.Kafka)30 ParallelTest (io.strimzi.test.annotations.ParallelTest)30 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)16 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)16 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 Container (io.fabric8.kubernetes.api.model.Container)8 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)8 ContainerEnvVar (io.strimzi.api.kafka.model.ContainerEnvVar)8 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)6 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)4 SecurityContext (io.fabric8.kubernetes.api.model.SecurityContext)4 SecurityContextBuilder (io.fabric8.kubernetes.api.model.SecurityContextBuilder)4 Capacity (io.strimzi.operator.cluster.model.cruisecontrol.Capacity)4 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)4 Affinity (io.fabric8.kubernetes.api.model.Affinity)2 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)2 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)2 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)2