Search in sources :

Example 11 with CruiseControlSpecBuilder

use of io.strimzi.api.kafka.model.CruiseControlSpecBuilder 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)

Example 12 with CruiseControlSpecBuilder

use of io.strimzi.api.kafka.model.CruiseControlSpecBuilder 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)));
}
Also used : CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Container(io.fabric8.kubernetes.api.model.Container) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with CruiseControlSpecBuilder

use of io.strimzi.api.kafka.model.CruiseControlSpecBuilder 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));
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) Toleration(io.fabric8.kubernetes.api.model.Toleration) Affinity(io.fabric8.kubernetes.api.model.Affinity) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 14 with CruiseControlSpecBuilder

use of io.strimzi.api.kafka.model.CruiseControlSpecBuilder in project strimzi-kafka-operator by strimzi.

the class CruiseControlTest method testBrokerCapacities.

@ParallelTest
public void testBrokerCapacities() {
    // Test user defined capacities
    BrokerCapacity userDefinedBrokerCapacity = new BrokerCapacity();
    userDefinedBrokerCapacity.setInboundNetwork("50000KB/s");
    userDefinedBrokerCapacity.setOutboundNetwork("50000KB/s");
    CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withBrokerCapacity(userDefinedBrokerCapacity).build();
    Kafka resource = createKafka(cruiseControlSpec);
    Capacity capacity = new Capacity(resource.getSpec(), kafkaStorage);
    assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.generateCapacityConfig()));
    // Test generated disk capacity
    JbodStorage jbodStorage = new JbodStorage();
    List<SingleVolumeStorage> volumes = new ArrayList<>();
    PersistentClaimStorage p1 = new PersistentClaimStorage();
    p1.setId(0);
    p1.setSize("50Gi");
    volumes.add(p1);
    PersistentClaimStorage p2 = new PersistentClaimStorage();
    p2.setId(1);
    volumes.add(p2);
    jbodStorage.setVolumes(volumes);
    resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().editKafka().withVersion(version).withStorage(jbodStorage).endKafka().withCruiseControl(cruiseControlSpec).endSpec().build();
    capacity = new Capacity(resource.getSpec(), jbodStorage);
    assertThat(getCapacityConfigurationFromEnvVar(resource, ENV_VAR_CRUISE_CONTROL_CAPACITY_CONFIGURATION), is(capacity.generateCapacityConfig()));
}
Also used : CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) BrokerCapacity(io.strimzi.api.kafka.model.balancing.BrokerCapacity) Capacity(io.strimzi.operator.cluster.model.cruisecontrol.Capacity) BrokerCapacity(io.strimzi.api.kafka.model.balancing.BrokerCapacity) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) Kafka(io.strimzi.api.kafka.model.Kafka) ArrayList(java.util.ArrayList) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 15 with CruiseControlSpecBuilder

use of io.strimzi.api.kafka.model.CruiseControlSpecBuilder in project strimzi-kafka-operator by strimzi.

the class CruiseControlTest method testContainerTemplateEnvVarsWithKeyConflict.

@ParallelTest
public void testContainerTemplateEnvVarsWithKeyConflict() {
    ContainerEnvVar envVar1 = new ContainerEnvVar();
    String testEnvOneKey = "TEST_ENV_1";
    String testEnvOneValue = "test.env.one";
    envVar1.setName(testEnvOneKey);
    envVar1.setValue(testEnvOneValue);
    ContainerEnvVar envVar2 = new ContainerEnvVar();
    String testEnvTwoKey = "TEST_ENV_2";
    String testEnvTwoValue = "my-special-value";
    envVar2.setName(testEnvTwoKey);
    envVar2.setValue(testEnvTwoValue);
    CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder().withImage(ccImage).withNewTemplate().withNewCruiseControlContainer().withEnv(envVar1, envVar2).endCruiseControlContainer().endTemplate().build();
    Kafka resource = createKafka(cruiseControlSpec);
    CruiseControl cc = createCruiseControl(resource);
    List<EnvVar> envVarList = cc.getEnvVars();
    assertThat(envVarList, hasItems(new EnvVar(testEnvOneKey, testEnvOneValue, null)));
    assertThat(envVarList, hasItems(new EnvVar(testEnvTwoKey, testEnvTwoValue, null)));
}
Also used : CruiseControlSpec(io.strimzi.api.kafka.model.CruiseControlSpec) Kafka(io.strimzi.api.kafka.model.Kafka) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) CruiseControlSpecBuilder(io.strimzi.api.kafka.model.CruiseControlSpecBuilder) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

CruiseControlSpec (io.strimzi.api.kafka.model.CruiseControlSpec)36 CruiseControlSpecBuilder (io.strimzi.api.kafka.model.CruiseControlSpecBuilder)36 Kafka (io.strimzi.api.kafka.model.Kafka)30 ParallelTest (io.strimzi.test.annotations.ParallelTest)30 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)16 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 Container (io.fabric8.kubernetes.api.model.Container)10 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)10 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 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)3 HashMap (java.util.HashMap)3 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