io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Get resource requirements from memory and cpu.
 *
 * @param mem Memory in mb.
 * @param cpu cpu.
 * @param externalResources external resources
 * @return KubernetesResource requirements.
 */
public static ResourceRequirements getResourceRequirements(int mem, double cpu, Map<String, Long> externalResources) {
	final Quantity cpuQuantity = new Quantity(String.valueOf(cpu));
	final Quantity memQuantity = new Quantity(mem + Constants.RESOURCE_UNIT_MB);

	ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder()
		.addToRequests(Constants.RESOURCE_NAME_MEMORY, memQuantity)
		.addToRequests(Constants.RESOURCE_NAME_CPU, cpuQuantity)
		.addToLimits(Constants.RESOURCE_NAME_MEMORY, memQuantity)
		.addToLimits(Constants.RESOURCE_NAME_CPU, cpuQuantity);

	// Add the external resources to resource requirement.
	for (Map.Entry<String, Long> externalResource: externalResources.entrySet()) {
		final Quantity resourceQuantity = new Quantity(String.valueOf(externalResource.getValue()));
		resourceRequirementsBuilder
			.addToRequests(externalResource.getKey(), resourceQuantity)
			.addToLimits(externalResource.getKey(), resourceQuantity);
		LOG.info("Request external resource {} with config key {}.", resourceQuantity.getAmount(), externalResource.getKey());
	}

	return resourceRequirementsBuilder.build();
}
 
Example #2
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
@Tag(MIRROR_MAKER2)
@Tag(CONNECT_COMPONENTS)
void testKafkaMirrorMaker2Status() {
    String mm2Url = KafkaMirrorMaker2Resources.url(CLUSTER_NAME, NAMESPACE, 8083);
    String targetClusterName = "target-cluster";
    KafkaResource.kafkaEphemeral(targetClusterName, 1, 1).done();
    KafkaMirrorMaker2Resource.kafkaMirrorMaker2(CLUSTER_NAME, CLUSTER_NAME, targetClusterName, 1, false).done();
    KafkaMirrorMaker2Utils.waitForKafkaMirrorMaker2Ready(CLUSTER_NAME);
    assertKafkaMirrorMaker2Status(1, mm2Url);

    // Corrupt Mirror Maker pods
    KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2Resource(CLUSTER_NAME, mm2 -> mm2.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100000000m"))
            .build()));
    KafkaMirrorMaker2Utils.waitForKafkaMirrorMaker2NotReady(CLUSTER_NAME);
    // Restore Mirror Maker pod
    KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2Resource(CLUSTER_NAME, mm2 -> mm2.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100m"))
            .build()));
    KafkaMirrorMaker2Utils.waitForKafkaMirrorMaker2Ready(CLUSTER_NAME);
    assertKafkaMirrorMaker2Status(3, mm2Url);
}
 
Example #3
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
@OpenShiftOnly
@Tag(CONNECT_S2I)
@Tag(CONNECT_COMPONENTS)
void testKafkaConnectS2IStatus() {
    String connectS2IDeploymentConfigName = KafkaConnectS2IResources.deploymentName(CONNECTS2I_CLUSTER_NAME);
    String connectS2IUrl = KafkaConnectS2IResources.url(CONNECTS2I_CLUSTER_NAME, NAMESPACE, 8083);

    KafkaConnectS2IResource.kafkaConnectS2I(CONNECTS2I_CLUSTER_NAME, CLUSTER_NAME, 1)
        .editMetadata()
            .addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true")
        .endMetadata().done();

    assertKafkaConnectS2IStatus(1, connectS2IUrl, connectS2IDeploymentConfigName);

    KafkaConnectS2IResource.replaceConnectS2IResource(CONNECTS2I_CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100000000m"))
            .build()));
    KafkaConnectS2IUtils.waitForConnectS2INotReady(CONNECTS2I_CLUSTER_NAME);

    KafkaConnectS2IResource.replaceConnectS2IResource(CONNECTS2I_CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100m"))
            .build()));
    KafkaConnectS2IUtils.waitForConnectS2IReady(CONNECTS2I_CLUSTER_NAME);
    assertKafkaConnectS2IStatus(3, connectS2IUrl, connectS2IDeploymentConfigName);
}
 
Example #4
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
void testKafkaBridgeStatus() {
    String bridgeUrl = KafkaBridgeResources.url(CLUSTER_NAME, NAMESPACE, 8080);
    KafkaBridgeResource.kafkaBridge(CLUSTER_NAME, KafkaResources.plainBootstrapAddress(CLUSTER_NAME), 1).done();
    KafkaBridgeUtils.waitForKafkaBridgeReady(CLUSTER_NAME);
    assertKafkaBridgeStatus(1, bridgeUrl);

    KafkaBridgeResource.replaceBridgeResource(CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100000000m"))
            .build()));
    KafkaBridgeUtils.waitForKafkaBridgeNotReady(CLUSTER_NAME);

    KafkaBridgeResource.replaceBridgeResource(CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("10m"))
            .build()));
    KafkaBridgeUtils.waitForKafkaBridgeReady(CLUSTER_NAME);
    assertKafkaBridgeStatus(3, bridgeUrl);
}
 
Example #5
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
@Tag(MIRROR_MAKER)
void testKafkaMirrorMakerStatus() {
    // Deploy Mirror Maker
    KafkaMirrorMakerResource.kafkaMirrorMaker(CLUSTER_NAME, CLUSTER_NAME, CLUSTER_NAME, "my-group" + rng.nextInt(Integer.MAX_VALUE), 1, false).done();
    KafkaMirrorMakerUtils.waitForKafkaMirrorMakerReady(CLUSTER_NAME);
    assertKafkaMirrorMakerStatus(1);
    // Corrupt Mirror Maker pods
    KafkaMirrorMakerResource.replaceMirrorMakerResource(CLUSTER_NAME, mm -> mm.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100000000m"))
            .build()));
    KafkaMirrorMakerUtils.waitForKafkaMirrorMakerNotReady(CLUSTER_NAME);
    // Restore Mirror Maker pod
    KafkaMirrorMakerResource.replaceMirrorMakerResource(CLUSTER_NAME, mm -> mm.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100m"))
            .build()));
    KafkaMirrorMakerUtils.waitForKafkaMirrorMakerReady(CLUSTER_NAME);
    assertKafkaMirrorMakerStatus(3);
}
 
Example #6
Source File: ContainerResourceProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOverridesContainerRamLimitAndRequestFromMachineAttribute() throws Exception {
  ResourceRequirements resourceRequirements =
      new ResourceRequirementsBuilder()
          .addToLimits(of("memory", new Quantity("3221225472"), "cpu", new Quantity("0.678")))
          .addToRequests(of("memory", new Quantity("1231231423"), "cpu", new Quantity("0.333")))
          .build();
  container.setResources(resourceRequirements);

  resourceProvisioner.provision(k8sEnv, identity);

  assertEquals(container.getResources().getLimits().get("memory").getAmount(), RAM_LIMIT_VALUE);
  assertEquals(container.getResources().getLimits().get("cpu").getAmount(), CPU_LIMIT_VALUE);
  assertEquals(
      container.getResources().getRequests().get("memory").getAmount(), RAM_REQUEST_VALUE);
  assertEquals(container.getResources().getRequests().get("cpu").getAmount(), CPU_REQUEST_VALUE);
}
 
Example #7
Source File: KafkaConnectS2IClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
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"));

    KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource)
            .editSpec()
                .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build())
            .endSpec()
            .build();
    KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS);

    DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getResources().getLimits(), is(limits));
    assertThat(cont.getResources().getRequests(), is(requests));
}
 
Example #8
Source File: KafkaMirrorMaker2ClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
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"));

    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource)
            .editSpec()
                .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build())
            .endSpec()
            .build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS);

    Deployment dep = kmm2.generateDeployment(Collections.EMPTY_MAP, true, null, null);
    Container cont = getContainer(dep);
    assertThat(cont.getResources().getLimits(), is(limits));
    assertThat(cont.getResources().getRequests(), is(requests));
}
 
Example #9
Source File: KafkaConnectClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
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"));

    KafkaConnect resource = new KafkaConnectBuilder(this.resource)
            .editSpec()
                .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build())
            .endSpec()
            .build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS);

    Deployment dep = kc.generateDeployment(Collections.EMPTY_MAP, true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getResources().getLimits(), is(limits));
    assertThat(cont.getResources().getRequests(), is(requests));
}
 
Example #10
Source File: KafkaMirrorMakerClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
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"));

    KafkaMirrorMaker resource = new KafkaMirrorMakerBuilder(this.resource)
            .editSpec()
                .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build())
            .endSpec()
            .build();
    KafkaMirrorMakerCluster mmc = KafkaMirrorMakerCluster.fromCrd(resource, VERSIONS);

    Deployment dep = mmc.generateDeployment(emptyMap(), true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getResources().getLimits(), is(limits));
    assertThat(cont.getResources().getRequests(), is(requests));
}
 
Example #11
Source File: KafkaBridgeClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
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"));

    KafkaBridge resource = new KafkaBridgeBuilder(this.resource)
            .editSpec()
                .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build())
            .endSpec()
            .build();
    KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(resource, VERSIONS);

    Deployment dep = kbc.generateDeployment(Collections.EMPTY_MAP, true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getResources().getLimits(), is(limits));
    assertThat(cont.getResources().getRequests(), is(requests));
}
 
Example #12
Source File: PVCSubPathHelperTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSetMemoryLimitAndRequest() throws Exception {
  when(podStatus.getPhase()).thenReturn(POD_PHASE_SUCCEEDED);

  pvcSubPathHelper.createDirs(
      identity, WORKSPACE_ID, PVC_NAME, emptyMap(), WORKSPACE_ID + PROJECTS_PATH);

  verify(osDeployments).create(podCaptor.capture());
  ResourceRequirements actual =
      podCaptor.getValue().getSpec().getContainers().get(0).getResources();
  ResourceRequirements expected =
      new ResourceRequirementsBuilder()
          .addToLimits(of("memory", new Quantity(jobMemoryLimit)))
          .addToRequests(of("memory", new Quantity(jobMemoryLimit)))
          .build();
  assertEquals(actual, expected);
  verify(osDeployments).wait(anyString(), anyInt(), any());
  verify(podStatus).getPhase();
  verify(osDeployments).delete(anyString());
  verify(securityContextProvisioner).provision(any());
}
 
Example #13
Source File: PodTemplateUtilsTest.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCombineAllResources() {
    Container container1 = new Container();
    container1.setResources(new ResourceRequirementsBuilder() //
            .addToLimits("cpu", new Quantity("1")) //
            .addToLimits("memory", new Quantity("1Gi")) //
            .addToRequests("cpu", new Quantity("100m")) //
            .addToRequests("memory", new Quantity("156Mi")) //
            .build());

    Container container2 = new Container();
    container2.setResources(new ResourceRequirementsBuilder() //
            .addToLimits("cpu", new Quantity("2")) //
            .addToLimits("memory", new Quantity("2Gi")) //
            .addToRequests("cpu", new Quantity("200m")) //
            .addToRequests("memory", new Quantity("256Mi")) //
            .build());

    Container result = combine(container1, container2);

    assertQuantity("2", result.getResources().getLimits().get("cpu"));
    assertQuantity("2Gi", result.getResources().getLimits().get("memory"));
    assertQuantity("200m", result.getResources().getRequests().get("cpu"));
    assertQuantity("256Mi", result.getResources().getRequests().get("memory"));
}
 
Example #14
Source File: CruiseControlTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
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 =
            new KafkaBuilder(ResourceUtils.createKafkaCluster(namespace, cluster, replicas, image, healthDelay, healthTimeout))
            .editSpec()
                .editKafka()
                    .withVersion(version)
                .endKafka()
                .withCruiseControl(cruiseControlSpec)
            .endSpec()
            .build();

    CruiseControl cc = CruiseControl.fromCrd(resource, VERSIONS);
    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().get();

    assertThat(ccContainer.getResources().getLimits(), is(limits));
    assertThat(ccContainer.getResources().getRequests(), is(requests));
}
 
Example #15
Source File: ConnectST.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
void testJvmAndResources() {
    KafkaResource.kafkaEphemeral(CLUSTER_NAME, 3).done();

    Map<String, String> jvmOptionsXX = new HashMap<>();
    jvmOptionsXX.put("UseG1GC", "true");

    KafkaConnectResource.kafkaConnect(CLUSTER_NAME, 1)
        .editMetadata()
            .addToLabels("type", "kafka-connect")
        .endMetadata()
        .editSpec()
            .withResources(new ResourceRequirementsBuilder()
                    .addToLimits("memory", new Quantity("400M"))
                    .addToLimits("cpu", new Quantity("2"))
                    .addToRequests("memory", new Quantity("300M"))
                    .addToRequests("cpu", new Quantity("1"))
                    .build())
                .withNewJvmOptions()
                    .withXmx("200m")
                    .withXms("200m")
                    .withServer(true)
                    .withXx(jvmOptionsXX)
                .endJvmOptions()
            .endSpec()
            .done();

    String podName = PodUtils.getPodNameByPrefix(KafkaConnectResources.deploymentName(CLUSTER_NAME));
    assertResources(NAMESPACE, podName, KafkaConnectResources.deploymentName(CLUSTER_NAME),
            "400M", "2", "300M", "1");
    assertExpectedJavaOpts(podName, KafkaConnectResources.deploymentName(CLUSTER_NAME),
            "-Xmx200m", "-Xms200m", "-server", "-XX:+UseG1GC");
}
 
Example #16
Source File: LanderPodFactory.java    From data-highway with Apache License 2.0 5 votes vote down vote up
private Container container(String roadName, List<String> args, Map<String, String> config, String truckParkName) {
  List<EnvVar> env = ImmutableList
      .<EnvVar> builder()
      .add(envFromFieldPath("KUBERNETES_NAMESPACE", "metadata.namespace"))
      .add(env("POD_NAME", truckParkName))
      .add(env("ENVIRONMENT", environment))
      .add(env("JVM_ARGS", config.get(JVM_ARGS)))
      .add(env("CLOUDWATCH_REGION", config.get(CLOUDWATCH_REGION)))
      .add(env("CLOUDWATCH_GROUP", config.get(CLOUDWATCH_GROUP)))
      .add(env("CLOUDWATCH_STREAM", "${KUBERNETES_NAMESPACE}-truck-park-" + roadName))
      .build();
  Map<String, Quantity> limits = ImmutableMap
      .<String, Quantity> builder()
      .put(CPU, new Quantity(config.get(CPU)))
      .put(MEMORY, new Quantity(config.get(MEMORY)))
      .build();
  return new ContainerBuilder()
      .withName(truckParkName)
      .withImage(config.get(DOCKER_IMAGE))
      .withArgs(args)
      .withEnv(env)
      .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(limits).build())
      .withLivenessProbe(new ProbeBuilder()
          .withHttpGet(new HTTPGetActionBuilder().withPath("/").withPort(new IntOrString("http")).build())
          .withInitialDelaySeconds(getConfigOrDefault(config, "livenessInitialDelay", 30))
          .withPeriodSeconds(getConfigOrDefault(config, "livenessPeriod", 5))
          .withSuccessThreshold(getConfigOrDefault(config, "livenessSuccessThreshold", 1))
          .withTimeoutSeconds(getConfigOrDefault(config, "livenessTimeout", 5))
          .withFailureThreshold(getConfigOrDefault(config, "livenessFailureThreshold", 3))
          .build())
      .build();
}
 
Example #17
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
@Tag(NODEPORT_SUPPORTED)
void testKafkaStatus() {
    LOGGER.info("Checking status of deployed kafka cluster");
    KafkaUtils.waitForKafkaReady(CLUSTER_NAME);

    BasicExternalKafkaClient basicExternalKafkaClient = new BasicExternalKafkaClient.Builder()
        .withTopicName(TOPIC_NAME)
        .withNamespaceName(NAMESPACE)
        .withClusterName(CLUSTER_NAME)
        .withMessageCount(MESSAGE_COUNT)
        .build();

    basicExternalKafkaClient.verifyProducedAndConsumedMessages(
        basicExternalKafkaClient.sendMessagesPlain(),
        basicExternalKafkaClient.receiveMessagesPlain()
    );

    assertKafkaStatus(1, "my-cluster-kafka-bootstrap.status-cluster-test.svc");

    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec().getEntityOperator().getTopicOperator().setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("100000m"))
                .build());
    });

    LOGGER.info("Wait until cluster will be in NotReady state ...");
    KafkaUtils.waitForKafkaNotReady(CLUSTER_NAME);

    LOGGER.info("Recovery cluster to Ready state ...");
    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec().getEntityOperator().getTopicOperator().setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("100m"))
                .build());
    });
    KafkaUtils.waitForKafkaReady(CLUSTER_NAME);
    assertKafkaStatus(3, "my-cluster-kafka-bootstrap.status-cluster-test.svc");
}
 
Example #18
Source File: KubeUtilTest.java    From enmasse with Apache License 2.0 5 votes vote down vote up
@Test
public void appliesContainerOrderIgnored() {
    Container actualFooContainer = new ContainerBuilder()
            .withName("foo").build();
    Container actualBarContainer = new ContainerBuilder()
            .withName("bar").build();

    Map<String, Quantity> widgets = Collections.singletonMap("widgets", new QuantityBuilder().withAmount("10").build());
    ResourceRequirements resources = new ResourceRequirementsBuilder().withLimits(widgets).build();
    Container desiredFooContainer = new ContainerBuilder()
            .withName("foo")
            .withResources(resources).build();

    PodTemplateSpec actual1 = new PodTemplateSpecBuilder()
            .withNewSpec()
            .addToContainers(actualBarContainer, actualFooContainer)
            .endSpec()
            .build();

    PodTemplateSpec desired = new PodTemplateSpecBuilder()
            .withNewSpec()
            .addToContainers(desiredFooContainer)
            .endSpec()
            .build();

    KubeUtil.applyPodTemplate(actual1, desired);

    PodTemplateSpec actual = actual1;

    Container barContainer = actual.getSpec().getContainers().get(0);
    assertThat(barContainer.getName(), equalTo("bar"));
    assertThat(barContainer.getResources(), nullValue());

    Container fooContainer = actual.getSpec().getContainers().get(1);
    assertThat(fooContainer.getName(), equalTo("foo"));
    assertThat(fooContainer.getResources(), equalTo(resources));
}
 
Example #19
Source File: KafkaCluster.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Container> getInitContainers(ImagePullPolicy imagePullPolicy) {
    List<Container> initContainers = new ArrayList<>(1);

    if (rack != null || isExposedWithNodePort()) {
        ResourceRequirements resources = new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("100m"))
                .addToRequests("memory", new Quantity("128Mi"))
                .addToLimits("cpu", new Quantity("1"))
                .addToLimits("memory", new Quantity("256Mi"))
                .build();

        Container initContainer = new ContainerBuilder()
                .withName(INIT_NAME)
                .withImage(initImage)
                .withArgs("/opt/strimzi/bin/kafka_init_run.sh")
                .withResources(resources)
                .withEnv(getInitContainerEnvVars())
                .withVolumeMounts(VolumeUtils.createVolumeMount(INIT_VOLUME_NAME, INIT_VOLUME_MOUNT))
                .withImagePullPolicy(determineImagePullPolicy(imagePullPolicy, initImage))
                .withSecurityContext(templateInitContainerSecurityContext)
                .build();

        initContainers.add(initContainer);
    }

    return initContainers;
}
 
Example #20
Source File: KubeUtilTest.java    From enmasse with Apache License 2.0 5 votes vote down vote up
@Test
public void appliesContainerResourcesToPodTemplate() {
    Container actualContainer = new ContainerBuilder()
            .withName("foo").build();
    Map<String, Quantity> widgets = Collections.singletonMap("widgets", new QuantityBuilder().withAmount("10").build());
    ResourceRequirements resources = new ResourceRequirementsBuilder().withLimits(widgets).build();
    Container desiredContainer = new ContainerBuilder()
            .withName("foo")
            .withResources(resources).build();

    PodTemplateSpec actual = doApplyContainers(actualContainer, desiredContainer);

    Container container = actual.getSpec().getContainers().get(0);
    assertThat(container.getResources(), equalTo(resources));
}
 
Example #21
Source File: K8sContainerResolverTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private static ResourceRequirements toK8sCPULimitRequestResources(String cpuLimit) {
  return new ResourceRequirementsBuilder()
      .addToLimits("cpu", new Quantity(cpuLimit))
      .addToRequests("cpu", new Quantity(cpuLimit))
      .build();
}
 
Example #22
Source File: K8sContainerResolverTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private static ResourceRequirements toK8sMemoryLimitRequestResources(String memLimit) {
  return new ResourceRequirementsBuilder()
      .addToLimits("memory", new Quantity(memLimit))
      .addToRequests("memory", new Quantity(memLimit))
      .build();
}
 
Example #23
Source File: ConnectS2IST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
void testJvmAndResources() {
    KafkaResource.kafkaEphemeral(CLUSTER_NAME, 3).done();

    final String kafkaConnectS2IName = "kafka-connect-s2i-name-4";

    Map<String, String> jvmOptionsXX = new HashMap<>();
    jvmOptionsXX.put("UseG1GC", "true");

    KafkaConnectS2I kafkaConnectS2I = KafkaConnectS2IResource.kafkaConnectS2IWithoutWait(KafkaConnectS2IResource.defaultKafkaConnectS2I(kafkaConnectS2IName, CLUSTER_NAME, 1)
        .editMetadata()
            .addToLabels("type", "kafka-connect-s2i")
        .endMetadata()
        .editSpec()
            .withResources(
                new ResourceRequirementsBuilder()
                    .addToLimits("memory", new Quantity("400M"))
                    .addToLimits("cpu", new Quantity("2"))
                    .addToRequests("memory", new Quantity("300M"))
                    .addToRequests("cpu", new Quantity("1"))
                    .build())
            .withBuildResources(
                new ResourceRequirementsBuilder()
                    .addToLimits("memory", new Quantity("1000M"))
                    .addToLimits("cpu", new Quantity("1000"))
                    .addToRequests("memory", new Quantity("400M"))
                    .addToRequests("cpu", new Quantity("1000"))
                    .build())
            .withNewJvmOptions()
                .withXmx("200m")
                .withXms("200m")
                .withServer(true)
                .withXx(jvmOptionsXX)
            .endJvmOptions()
        .endSpec().build());

    KafkaConnectS2IUtils.waitForConnectS2INotReady(kafkaConnectS2IName);

    TestUtils.waitFor("build status: Pending", Constants.GLOBAL_POLL_INTERVAL, Constants.TIMEOUT_AVAILABILITY_TEST,
        () -> kubeClient().getClient().adapt(OpenShiftClient.class).builds().inNamespace(NAMESPACE).withName(kafkaConnectS2IName + "-connect-1").get().getStatus().getPhase().equals("Pending"));

    kubeClient().getClient().adapt(OpenShiftClient.class).builds().inNamespace(NAMESPACE).withName(kafkaConnectS2IName + "-connect-1").cascading(true).delete();

    KafkaConnectS2IResource.replaceConnectS2IResource(kafkaConnectS2IName, kc -> {
        kc.getSpec().setBuildResources(new ResourceRequirementsBuilder()
                .addToLimits("memory", new Quantity("1000M"))
                .addToLimits("cpu", new Quantity("1"))
                .addToRequests("memory", new Quantity("400M"))
                .addToRequests("cpu", new Quantity("1"))
                .build());
    });

    TestUtils.waitFor("KafkaConnect change", Constants.GLOBAL_POLL_INTERVAL, Constants.TIMEOUT_FOR_RESOURCE_READINESS,
        () -> kubeClient().getClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(NAMESPACE).withName(kafkaConnectS2IName + "-connect").get().getSpec().getResources().getRequests().get("cpu").equals(new Quantity("1")));

    cmdKubeClient().exec("start-build", KafkaConnectS2IResources.deploymentName(kafkaConnectS2IName), "-n", NAMESPACE);

    KafkaConnectS2IUtils.waitForConnectS2IReady(kafkaConnectS2IName);

    String podName = kubeClient().listPods("type", "kafka-connect-s2i").get(0).getMetadata().getName();

    TestUtils.waitFor("Resources are changed", Constants.GLOBAL_POLL_INTERVAL, Constants.TIMEOUT_FOR_RESOURCE_CREATION, () -> {
        try {
            assertResources(NAMESPACE, podName, kafkaConnectS2IName + "-connect",
                    "400M", "2", "300M", "1");
            assertExpectedJavaOpts(podName, kafkaConnectS2IName + "-connect",
                    "-Xmx200m", "-Xms200m", "-server", "-XX:+UseG1GC");
            return true;
        } catch (Exception e) {
            return false;
        }
    });

    KafkaConnectS2IResource.deleteKafkaConnectS2IWithoutWait(kafkaConnectS2IName);
    DeploymentConfigUtils.waitForDeploymentConfigDeletion(KafkaConnectS2IResources.deploymentName(kafkaConnectS2IName));
}
 
Example #24
Source File: MirrorMakerST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
void testMirrorMaker() {
    Map<String, String> jvmOptionsXX = new HashMap<>();
    jvmOptionsXX.put("UseG1GC", "true");
    timeMeasuringSystem.setOperationID(timeMeasuringSystem.startTimeMeasuring(Operation.MM_DEPLOYMENT));
    String topicSourceName = TOPIC_NAME + "-source" + "-" + rng.nextInt(Integer.MAX_VALUE);

    // Deploy source kafka
    KafkaResource.kafkaEphemeral(kafkaClusterSourceName, 1, 1).done();
    // Deploy target kafka
    KafkaResource.kafkaEphemeral(kafkaClusterTargetName, 1, 1).done();
    // Deploy Topic
    KafkaTopicResource.topic(kafkaClusterSourceName, topicSourceName).done();

    KafkaClientsResource.deployKafkaClients(false, CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).done();

    final String kafkaClientsPodName = kubeClient().listPodsByPrefixInName(CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();

    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder()
        .withUsingPodName(kafkaClientsPodName)
        .withTopicName("topic-for-test-broker-1")
        .withNamespaceName(NAMESPACE)
        .withClusterName(kafkaClusterSourceName)
        .withMessageCount(messagesCount)
        .withConsumerGroupName(CONSUMER_GROUP_NAME + "-" + rng.nextInt(Integer.MAX_VALUE))
        .build();

    // Check brokers availability
    internalKafkaClient.checkProducedAndConsumedMessages(
        internalKafkaClient.sendMessagesPlain(),
        internalKafkaClient.receiveMessagesPlain()
    );

    internalKafkaClient.setTopicName("topic-for-test-broker-2");
    internalKafkaClient.setClusterName(kafkaClusterTargetName);

    internalKafkaClient.checkProducedAndConsumedMessages(
        internalKafkaClient.sendMessagesPlain(),
        internalKafkaClient.receiveMessagesPlain()
    );

    // Deploy Mirror Maker
    KafkaMirrorMakerResource.kafkaMirrorMaker(CLUSTER_NAME, kafkaClusterSourceName, kafkaClusterTargetName, "my-group" + rng.nextInt(Integer.MAX_VALUE), 1, false).
            editSpec()
            .withResources(new ResourceRequirementsBuilder()
                    .addToLimits("memory", new Quantity("400M"))
                    .addToLimits("cpu", new Quantity("2"))
                    .addToRequests("memory", new Quantity("300M"))
                    .addToRequests("cpu", new Quantity("1"))
                    .build())
            .withNewJvmOptions()
                .withXmx("200m")
                .withXms("200m")
                .withServer(true)
                .withXx(jvmOptionsXX)
            .endJvmOptions()
            .endSpec().done();

    verifyLabelsOnPods(CLUSTER_NAME, "mirror-maker", null, "KafkaMirrorMaker");
    verifyLabelsForService(CLUSTER_NAME, "mirror-maker", "KafkaMirrorMaker");

    verifyLabelsForConfigMaps(kafkaClusterSourceName, null, kafkaClusterTargetName);
    verifyLabelsForServiceAccounts(kafkaClusterSourceName, null);

    String mirrorMakerPodName = kubeClient().listPodsByPrefixInName(KafkaMirrorMakerResources.deploymentName(CLUSTER_NAME)).get(0).getMetadata().getName();
    String kafkaMirrorMakerLogs = kubeClient().logs(mirrorMakerPodName);

    assertThat(kafkaMirrorMakerLogs,
        not(containsString("keytool error: java.io.FileNotFoundException: /opt/kafka/consumer-oauth-certs/**/* (No such file or directory)")));

    String podName = kubeClient().listPods().stream().filter(n -> n.getMetadata().getName().startsWith(KafkaMirrorMakerResources.deploymentName(CLUSTER_NAME))).findFirst().get().getMetadata().getName();
    assertResources(NAMESPACE, podName, CLUSTER_NAME.concat("-mirror-maker"),
            "400M", "2", "300M", "1");
    assertExpectedJavaOpts(podName, KafkaMirrorMakerResources.deploymentName(CLUSTER_NAME),
            "-Xmx200m", "-Xms200m", "-server", "-XX:+UseG1GC");

    timeMeasuringSystem.stopOperation(timeMeasuringSystem.getOperationID());

    internalKafkaClient.setTopicName(topicSourceName);
    internalKafkaClient.setClusterName(kafkaClusterSourceName);

    int sent = internalKafkaClient.sendMessagesPlain();

    internalKafkaClient.checkProducedAndConsumedMessages(
        sent,
        internalKafkaClient.receiveMessagesPlain()
    );

    internalKafkaClient.setClusterName(kafkaClusterTargetName);

    internalKafkaClient.checkProducedAndConsumedMessages(
        sent,
        internalKafkaClient.receiveMessagesPlain()
    );
}
 
Example #25
Source File: CustomResourceStatusST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
@Tag(CONNECT)
@Tag(CONNECTOR_OPERATOR)
@Tag(CONNECT_COMPONENTS)
void testKafkaConnectAndConnectorStatus() {
    String connectUrl = KafkaConnectResources.url(CLUSTER_NAME, NAMESPACE, 8083);
    KafkaConnectResource.kafkaConnect(CLUSTER_NAME, 1)
        .editMetadata()
            .addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true")
        .endMetadata().done();

    KafkaConnectorResource.kafkaConnector(CLUSTER_NAME).done();

    assertKafkaConnectStatus(1, connectUrl);
    assertKafkaConnectorStatus(CLUSTER_NAME, 1, "RUNNING|UNASSIGNED", 0, "RUNNING", "source");

    KafkaConnectResource.replaceKafkaConnectResource(CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100000000m"))
            .build()));
    KafkaConnectUtils.waitForConnectNotReady(CLUSTER_NAME);

    KafkaConnectResource.replaceKafkaConnectResource(CLUSTER_NAME, kb -> kb.getSpec().setResources(new ResourceRequirementsBuilder()
            .addToRequests("cpu", new Quantity("100m"))
            .build()));
    KafkaConnectUtils.waitForConnectReady(CLUSTER_NAME);
    assertKafkaConnectStatus(3, connectUrl);

    KafkaConnectorResource.replaceKafkaConnectorResource(CLUSTER_NAME,
        kc -> kc.getMetadata().setLabels(Collections.singletonMap(Labels.STRIMZI_CLUSTER_LABEL, "non-existing-connect-cluster")));
    KafkaConnectorUtils.waitForConnectorNotReady(CLUSTER_NAME);
    assertThat(KafkaConnectorResource.kafkaConnectorClient().inNamespace(NAMESPACE).withName(CLUSTER_NAME).get().getStatus().getConnectorStatus(), is(nullValue()));

    KafkaConnectorResource.replaceKafkaConnectorResource(CLUSTER_NAME,
        kc -> kc.getMetadata().setLabels(Collections.singletonMap(Labels.STRIMZI_CLUSTER_LABEL, CLUSTER_NAME)));
    KafkaConnectorUtils.waitForConnectorReady(CLUSTER_NAME);
    assertKafkaConnectorStatus(CLUSTER_NAME, 1, "RUNNING|UNASSIGNED", 0, "RUNNING", "source");

    String defaultClass = KafkaConnectorResource.kafkaConnectorClient().inNamespace(NAMESPACE).withName(CLUSTER_NAME).get().getSpec().getClassName();

    KafkaConnectorResource.replaceKafkaConnectorResource(CLUSTER_NAME,
        kc -> kc.getSpec().setClassName("non-existing-class"));
    KafkaConnectorUtils.waitForConnectorNotReady(CLUSTER_NAME);
    assertThat(KafkaConnectorResource.kafkaConnectorClient().inNamespace(NAMESPACE).withName(CLUSTER_NAME).get().getStatus().getConnectorStatus(), is(nullValue()));

    KafkaConnectorResource.replaceKafkaConnectorResource(CLUSTER_NAME,
        kc -> {
            kc.getMetadata().setLabels(Collections.singletonMap(Labels.STRIMZI_CLUSTER_LABEL, CLUSTER_NAME));
            kc.getSpec().setClassName(defaultClass);
        });

    KafkaConnectorUtils.waitForConnectorReady(CLUSTER_NAME);
    assertKafkaConnectorStatus(CLUSTER_NAME, 3, "RUNNING|UNASSIGNED", 0, "RUNNING", "source");
}
 
Example #26
Source File: RollingUpdateST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
void testRecoveryDuringKafkaRollingUpdate() throws Exception {
    String topicName = KafkaTopicUtils.generateRandomNameOfTopic();

    KafkaResource.kafkaPersistent(CLUSTER_NAME, 3, 3).done();
    KafkaTopicResource.topic(CLUSTER_NAME, topicName, 2, 3).done();

    String userName = KafkaUserUtils.generateRandomNameOfKafkaUser();
    KafkaUser user = KafkaUserResource.tlsUser(CLUSTER_NAME, userName).done();

    KafkaClientsResource.deployKafkaClients(true, CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS, user).done();

    final String defaultKafkaClientsPodName =
            ResourceManager.kubeClient().listPodsByPrefixInName(CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();

    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder()
        .withUsingPodName(defaultKafkaClientsPodName)
        .withTopicName(topicName)
        .withNamespaceName(NAMESPACE)
        .withClusterName(CLUSTER_NAME)
        .withMessageCount(MESSAGE_COUNT)
        .withKafkaUsername(userName)
        .build();

    int sent = internalKafkaClient.sendMessagesTls();
    assertThat(sent, is(MESSAGE_COUNT));

    LOGGER.info("Update resources for pods");

    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec()
            .getKafka()
            .setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("100000m"))
                .build());
    });

    ClientUtils.waitUntilClientReceivedMessagesTls(internalKafkaClient, MESSAGE_COUNT);

    internalKafkaClient.setConsumerGroup(CONSUMER_GROUP_NAME + "-" + rng.nextInt(Integer.MAX_VALUE));

    PodUtils.waitForPendingPod(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME));
    LOGGER.info("Verifying stability of kafka pods except the one, which is in pending phase");
    PodUtils.verifyThatRunningPodsAreStable(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME));

    LOGGER.info("Verifying stability of zookeeper pods");
    PodUtils.verifyThatRunningPodsAreStable(KafkaResources.zookeeperStatefulSetName(CLUSTER_NAME));

    ClientUtils.waitUntilClientReceivedMessagesTls(internalKafkaClient, MESSAGE_COUNT);

    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec()
            .getKafka()
            .setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("200m"))
                .build());
    });

    StatefulSetUtils.waitForAllStatefulSetPodsReady(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME), 3);

    internalKafkaClient.setConsumerGroup(CONSUMER_GROUP_NAME + "-" + rng.nextInt(Integer.MAX_VALUE));

    ClientUtils.waitUntilClientReceivedMessagesTls(internalKafkaClient, MESSAGE_COUNT);

    // Create new topic to ensure, that ZK is working properly
    String newTopicName = "new-test-topic-" + new Random().nextInt(Integer.MAX_VALUE);
    KafkaTopicResource.topic(CLUSTER_NAME, newTopicName, 1, 1).done();

    internalKafkaClient.setTopicName(newTopicName);
    internalKafkaClient.setConsumerGroup("group" + new Random().nextInt(Integer.MAX_VALUE));

    sent = internalKafkaClient.sendMessagesTls();
    assertThat(sent, is(MESSAGE_COUNT));
    int received = internalKafkaClient.receiveMessagesTls();
    assertThat(received, is(sent));

}
 
Example #27
Source File: RollingUpdateST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
void testRecoveryDuringZookeeperRollingUpdate() throws Exception {
    String topicName = KafkaTopicUtils.generateRandomNameOfTopic();

    KafkaResource.kafkaPersistent(CLUSTER_NAME, 3, 3).done();
    KafkaTopicResource.topic(CLUSTER_NAME, topicName, 2, 2).done();

    String userName = KafkaUserUtils.generateRandomNameOfKafkaUser();
    KafkaUser user = KafkaUserResource.tlsUser(CLUSTER_NAME, userName).done();

    KafkaClientsResource.deployKafkaClients(true, CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS, user).done();
    final String defaultKafkaClientsPodName =
            ResourceManager.kubeClient().listPodsByPrefixInName(CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();

    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder()
        .withUsingPodName(defaultKafkaClientsPodName)
        .withTopicName(topicName)
        .withNamespaceName(NAMESPACE)
        .withClusterName(CLUSTER_NAME)
        .withMessageCount(MESSAGE_COUNT)
        .withKafkaUsername(userName)
        .build();

    int sent = internalKafkaClient.sendMessagesTls();

    assertThat(sent, is(MESSAGE_COUNT));

    LOGGER.info("Update resources for pods");

    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec()
            .getZookeeper()
            .setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("100000m"))
                .build());
    });

    ClientUtils.waitUntilClientReceivedMessagesTls(internalKafkaClient, MESSAGE_COUNT);

    PodUtils.waitForPendingPod(KafkaResources.zookeeperStatefulSetName(CLUSTER_NAME));
    LOGGER.info("Verifying stability of zookeper pods except the one, which is in pending phase");
    PodUtils.verifyThatRunningPodsAreStable(KafkaResources.zookeeperStatefulSetName(CLUSTER_NAME));

    LOGGER.info("Verifying stability of kafka pods");
    PodUtils.verifyThatRunningPodsAreStable(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME));

    internalKafkaClient.setConsumerGroup(CONSUMER_GROUP_NAME + "-" + rng.nextInt(Integer.MAX_VALUE));

    ClientUtils.waitUntilClientReceivedMessagesTls(internalKafkaClient, MESSAGE_COUNT);

    KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> {
        k.getSpec()
            .getZookeeper()
            .setResources(new ResourceRequirementsBuilder()
                .addToRequests("cpu", new Quantity("200m"))
                .build());
    });

    StatefulSetUtils.waitForAllStatefulSetPodsReady(KafkaResources.zookeeperStatefulSetName(CLUSTER_NAME), 3);

    internalKafkaClient.setConsumerGroup(CONSUMER_GROUP_NAME + "-" + new Random().nextInt(Integer.MAX_VALUE));

    int received = internalKafkaClient.receiveMessagesTls();
    assertThat(received, is(sent));

    // Create new topic to ensure, that ZK is working properly
    String newTopicName = "new-test-topic-" + new Random().nextInt(Integer.MAX_VALUE);
    KafkaTopicResource.topic(CLUSTER_NAME, newTopicName, 1, 1).done();

    internalKafkaClient.setTopicName(newTopicName);
    internalKafkaClient.setConsumerGroup(CONSUMER_GROUP_NAME + "-" + new Random().nextInt(Integer.MAX_VALUE));

    sent = internalKafkaClient.sendMessagesTls();
    assertThat(sent, is(MESSAGE_COUNT));
    received = internalKafkaClient.receiveMessagesTls();
    assertThat(received, is(sent));
}
 
Example #28
Source File: AbstractModelTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
private ResourceRequirements getResourceRequest() {
    return new ResourceRequirementsBuilder()
            .addToRequests("memory", new Quantity("16000000000")).build();
}
 
Example #29
Source File: KafkaAssemblyOperatorMockTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static Iterable<KafkaAssemblyOperatorMockTest.Params> data() {
    int[] replicas = {1, 3};
    Storage[] kafkaStorageConfigs = {
        new EphemeralStorage(),
        new PersistentClaimStorageBuilder()
            .withSize("123")
            .withStorageClass("foo")
            .withDeleteClaim(true)
            .build(),
        new PersistentClaimStorageBuilder()
            .withSize("123")
            .withStorageClass("foo")
            .withDeleteClaim(false)
            .build()
    };
    SingleVolumeStorage[] zkStorageConfigs = {
        new EphemeralStorage(),
        new PersistentClaimStorageBuilder()
                .withSize("123")
                .withStorageClass("foo")
                .withDeleteClaim(true)
                .build(),
        new PersistentClaimStorageBuilder()
                .withSize("123")
                .withStorageClass("foo")
                .withDeleteClaim(false)
                .build()
    };
    ResourceRequirements[] resources = {
        new ResourceRequirementsBuilder()
            .addToLimits("cpu", new Quantity("5000m"))
            .addToLimits("memory", new Quantity("5000m"))
            .addToRequests("cpu", new Quantity("5000"))
            .addToRequests("memory", new Quantity("5000m"))
            .build()
    };
    List<KafkaAssemblyOperatorMockTest.Params> result = new ArrayList();

    for (int zkReplica : replicas) {
        for (SingleVolumeStorage zkStorage : zkStorageConfigs) {
            for (int kafkaReplica : replicas) {
                for (Storage kafkaStorage : kafkaStorageConfigs) {
                    for (ResourceRequirements resource : resources) {
                        result.add(new KafkaAssemblyOperatorMockTest.Params(
                                zkReplica, zkStorage,
                                kafkaReplica, kafkaStorage, resource));
                    }
                }
            }
        }
    }

    return result;
}
 
Example #30
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
public void testCpuResources() {
    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("cpu", new Quantity("1000m")))
                    .addToRequests(singletonMap("memory", new Quantity("1.1Gi")))
                    .addToLimits(singletonMap("cpu", new Quantity("1000m")))
                    .addToLimits(singletonMap("memory", new Quantity("500Mi")))
                    .build(),
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("cpu", new Quantity("1")))
                    .addToRequests(singletonMap("memory", new Quantity("1181116006")))
                    .addToLimits(singletonMap("cpu", new Quantity("1")))
                    .addToLimits(singletonMap("memory", new Quantity("524288000")))
                    .build()).isEmpty(), is(true));

    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("cpu", new Quantity("1001m")))
                    .build(),
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("cpu", new Quantity("1")))
                    .build()).isEmpty(), is(false));

    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("memory", new Quantity("1.1Gi")))
                    .build(),
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("memory", new Quantity("1181116007")))
                    .build()).isEmpty(), is(false));

    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .build(),
            new ResourceRequirementsBuilder()
                    .addToRequests(singletonMap("memory", new Quantity("1181116007")))
                    .build()).isEmpty(), is(false));

    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .build(),
            new ResourceRequirementsBuilder()
                    .build()).isEmpty(), is(true));

    assertThat(testCpuResources(
            new ResourceRequirementsBuilder()
                    .build(),
            null).isEmpty(), is(true));
}