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

The following examples show how to use io.fabric8.kubernetes.api.model.ResourceRequirements. 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: InitJobManagerDecorator.java    From flink with Apache License 2.0 6 votes vote down vote up
private Container decorateMainContainer(Container container) {
	final ResourceRequirements requirements = KubernetesUtils.getResourceRequirements(
			kubernetesJobManagerParameters.getJobManagerMemoryMB(),
			kubernetesJobManagerParameters.getJobManagerCPU(),
			Collections.emptyMap());

	return new ContainerBuilder(container)
			.withName(kubernetesJobManagerParameters.getJobManagerMainContainerName())
			.withImage(kubernetesJobManagerParameters.getImage())
			.withImagePullPolicy(kubernetesJobManagerParameters.getImagePullPolicy().name())
			.withResources(requirements)
			.withPorts(getContainerPorts())
			.withEnv(getCustomizedEnvs())
			.addNewEnv()
				.withName(ENV_FLINK_POD_IP_ADDRESS)
				.withValueFrom(new EnvVarSourceBuilder()
					.withNewFieldRef(API_VERSION, POD_IP_FIELD_PATH)
					.build())
				.endEnv()
			.build();
}
 
Example #3
Source File: InitTaskManagerDecorator.java    From flink with Apache License 2.0 6 votes vote down vote up
private Container decorateMainContainer(Container container) {
	final ResourceRequirements resourceRequirements = KubernetesUtils.getResourceRequirements(
			kubernetesTaskManagerParameters.getTaskManagerMemoryMB(),
			kubernetesTaskManagerParameters.getTaskManagerCPU(),
			kubernetesTaskManagerParameters.getTaskManagerExternalResources());

	return new ContainerBuilder(container)
			.withName(kubernetesTaskManagerParameters.getTaskManagerMainContainerName())
			.withImage(kubernetesTaskManagerParameters.getImage())
			.withImagePullPolicy(kubernetesTaskManagerParameters.getImagePullPolicy().name())
			.withResources(resourceRequirements)
			.withPorts(new ContainerPortBuilder()
				.withName(Constants.TASK_MANAGER_RPC_PORT_NAME)
				.withContainerPort(kubernetesTaskManagerParameters.getRPCPort())
				.build())
			.withEnv(getCustomizedEnvs())
			.build();
}
 
Example #4
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 #5
Source File: KubernetesEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private static PodData createPodData(String machineName, long ramLimit, long ramRequest) {
  final String containerName = "container_" + machineName;
  final Container containerMock = mock(Container.class);
  final ResourceRequirements resourcesMock = mock(ResourceRequirements.class);
  final Quantity limitQuantityMock = mock(Quantity.class);
  final Quantity requestQuantityMock = mock(Quantity.class);
  final PodSpec specMock = mock(PodSpec.class);
  final ObjectMeta metadataMock = mock(ObjectMeta.class);
  when(limitQuantityMock.getAmount()).thenReturn(String.valueOf(ramLimit));
  when(requestQuantityMock.getAmount()).thenReturn(String.valueOf(ramRequest));
  when(resourcesMock.getLimits()).thenReturn(ImmutableMap.of("memory", limitQuantityMock));
  when(resourcesMock.getRequests()).thenReturn(ImmutableMap.of("memory", requestQuantityMock));
  when(containerMock.getName()).thenReturn(containerName);
  when(containerMock.getResources()).thenReturn(resourcesMock);
  when(metadataMock.getAnnotations())
      .thenReturn(Names.createMachineNameAnnotations(containerName, machineName));
  when(specMock.getContainers()).thenReturn(ImmutableList.of(containerMock));
  return new PodData(specMock, metadataMock);
}
 
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: KubeUtil.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public static void applyCpuMemory(PodTemplateSpec podTemplateSpec, String cpu, String memory) {
    Map<String, Quantity> resources = new LinkedHashMap<>();
    if (cpu != null) {
        resources.put("cpu", new Quantity(cpu));
    }
    if (memory != null) {
        resources.put("memory", new Quantity(memory));
    }

    for (Container container : podTemplateSpec.getSpec().getContainers()) {
        if (container.getResources() == null) {
            container.setResources(new ResourceRequirements());
        }

        if (container.getResources().getRequests() == null) {
            container.getResources().setRequests(new LinkedHashMap<>());
        }
        container.getResources().getRequests().putAll(resources);

        if (container.getResources().getLimits() == null) {
            container.getResources().setLimits(new LinkedHashMap<>());
        }

        container.getResources().getLimits().putAll(resources);
    }
}
 
Example #8
Source File: AbstractModelTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getStringStringMap(String xmx, String xms, double dynamicFraction, long dynamicMax, ResourceRequirements resources) {
    Kafka resource = new KafkaBuilder()
            .withNewMetadata()
            .endMetadata()
            .build();
    AbstractModel am = new AbstractModel(resource, "") {
        @Override
        protected String getDefaultLogConfigFileName() {
            return "";
        }

        @Override
        protected List<Container> getContainers(ImagePullPolicy imagePullPolicy) {
            return emptyList();
        }
    };

    am.setLabels(Labels.forStrimziCluster("foo"));
    am.setJvmOptions(jvmOptions(xmx, xms));
    am.setResources(resources);
    List<EnvVar> envVars = new ArrayList<>(1);
    am.heapOptions(envVars, dynamicFraction, dynamicMax);
    return envVars.stream().collect(Collectors.toMap(e -> e.getName(), e -> e.getValue()));
}
 
Example #9
Source File: KubernetesDockerRunnerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConfigureResourceRequirements() {
  final String memRequest = "17Mi";
  final String memLimit = "4711Mi";
  final Pod pod = createPod(WORKFLOW_INSTANCE, RunSpec.builder()
      .executionId("eid1")
      .imageName("busybox")
      .memRequest(memRequest)
      .memLimit(memLimit)
      .build(),
      EMPTY_SECRET_SPEC);

  final ResourceRequirements resourceReqs = pod.getSpec().getContainers().get(0).getResources();
  assertThat(resourceReqs.getRequests().get("memory"), is(new Quantity(memRequest)));
  assertThat(resourceReqs.getLimits().get("memory"), is(new Quantity(memLimit)));
}
 
Example #10
Source File: ResourceUtils.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Generate ConfigMap for Kafka Connect S2I cluster
 */
public static KafkaConnectS2I createKafkaConnectS2ICluster(String clusterCmNamespace, String clusterCmName, int replicas,
                                                           String image, int healthDelay, int healthTimeout, String metricsCmJson,
                                                           String connectConfig, boolean insecureSourceRepo, String bootstrapServers,
                                                           ResourceRequirements builResourceRequirements) {

    return new KafkaConnectS2IBuilder(createEmptyKafkaConnectS2ICluster(clusterCmNamespace, clusterCmName))
            .withNewSpec()
                .withImage(image)
                .withReplicas(replicas)
                .withBootstrapServers(bootstrapServers)
                .withLivenessProbe(new Probe(healthDelay, healthTimeout))
                .withReadinessProbe(new Probe(healthDelay, healthTimeout))
                .withMetrics((Map<String, Object>) TestUtils.fromJson(metricsCmJson, Map.class))
                .withConfig((Map<String, Object>) TestUtils.fromJson(connectConfig, Map.class))
                .withInsecureSourceRepository(insecureSourceRepo)
                .withBuildResources(builResourceRequirements)
            .endSpec().build();
}
 
Example #11
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerRamRequestWhenResourceIsNull() {
  when(container.getResources()).thenReturn(null);

  Containers.addRamRequest(container, RAM_REQUEST);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getRequests().get("memory").getAmount(), String.valueOf(RAM_REQUEST));
}
 
Example #12
Source File: InitTaskManagerDecoratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalResourceInResourceRequirements() {
	final ResourceRequirements resourceRequirements = this.resultMainContainer.getResources();

	final Map<String, Quantity> requests = resourceRequirements.getRequests();
	assertEquals(Long.toString(RESOURCE_AMOUNT), requests.get(RESOURCE_CONFIG_KEY).getAmount());

	final Map<String, Quantity> limits = resourceRequirements.getLimits();
	assertEquals(Long.toString(RESOURCE_AMOUNT), limits.get(RESOURCE_CONFIG_KEY).getAmount());
}
 
Example #13
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerCPURequestWhenResourceIsNull() {
  when(container.getResources()).thenReturn(null);

  Containers.addCpuRequest(container, CPU_REQUEST);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getRequests().get("cpu").getAmount(), String.valueOf(CPU_REQUEST));
}
 
Example #14
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerRamLimitWhenResourceDoesNotContainAnyLimits() {
  when(resource.getLimits()).thenReturn(null);

  Containers.addRamLimit(container, RAM_LIMIT);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("memory").getAmount(), String.valueOf(RAM_LIMIT));
}
 
Example #15
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerCPULimitWhenResourceDoesNotContainAnyLimits() {
  when(resource.getLimits()).thenReturn(null);

  Containers.addCpuLimit(container, CPU_LIMIT);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("cpu").getAmount(), String.valueOf(CPU_LIMIT));
}
 
Example #16
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerRamRequestWhenResourceDoesNotContainAnyLimits() {
  when(resource.getLimits()).thenReturn(null);

  Containers.addRamRequest(container, RAM_REQUEST);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getRequests().get("memory").getAmount(), String.valueOf(RAM_REQUEST));
}
 
Example #17
Source File: PodTemplateBuilderTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultRequests() throws Exception {
    PodTemplate template = new PodTemplate();
    Pod pod = new PodTemplateBuilder(template).build();
    ResourceRequirements resources = pod.getSpec().getContainers().get(0).getResources();
    assertNotNull(resources);
    Map<String, Quantity> requests = resources.getRequests();
    assertNotNull(requests);
    PodTemplateUtilsTest.assertQuantity(PodTemplateBuilder.DEFAULT_JNLP_CONTAINER_CPU_REQUEST, requests.get("cpu"));
    PodTemplateUtilsTest.assertQuantity(PodTemplateBuilder.DEFAULT_JNLP_CONTAINER_MEMORY_REQUEST, requests.get("memory"));
}
 
Example #18
Source File: K8sContainerResolverTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test(dataProvider = "cpuLimitResourcesProvider")
public void shouldProvisionSidecarCPULimitAndRequest(
    String sidecarCpuLimit, ResourceRequirements resources) throws Exception {
  cheContainer.setCpuLimit(sidecarCpuLimit);
  cheContainer.setCpuRequest(sidecarCpuLimit);

  Container container = resolver.resolve();

  assertEquals(container.getResources(), 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: PodTemplateUtils.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
private static Map<String, Quantity> combineResources(Container parent, Container template,
                                                      Function<ResourceRequirements,
                                                               Map<String, Quantity>> resourceTypeMapper) {
    return Stream.of(template.getResources(), parent.getResources()) //
            .filter(Objects::nonNull) //
            .map(resourceTypeMapper) //
            .filter(Objects::nonNull) //
            .map(Map::entrySet) //
            .flatMap(Collection::stream) //
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1) // v2 (parent) loses
            );
}
 
Example #21
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerCPULimitWhenResourceIsNull() {
  when(container.getResources()).thenReturn(null);

  Containers.addCpuLimit(container, CPU_LIMIT);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("cpu").getAmount(), String.valueOf(CPU_LIMIT));
}
 
Example #22
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testAddContainerRamLimitWhenResourceIsNull() {
  when(container.getResources()).thenReturn(null);

  Containers.addRamLimit(container, RAM_LIMIT);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("memory").getAmount(), String.valueOf(RAM_LIMIT));
}
 
Example #23
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the CPU request in bytes, if it is present in given container otherwise 0 will be
 * returned.
 */
public static float getCpuRequest(Container container) {
  final ResourceRequirements resources = container.getResources();
  final Quantity quantity;
  if (resources != null
      && resources.getRequests() != null
      && (quantity = resources.getRequests().get("cpu")) != null
      && quantity.getAmount() != null) {
    return KubernetesSize.toCores(quantity.getAmount());
  }
  return 0;
}
 
Example #24
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the CPU limit in cores, if it is present in given container otherwise 0 will be
 * returned.
 */
public static float getCpuLimit(Container container) {
  final ResourceRequirements resources = container.getResources();
  final Quantity quantity;
  if (resources != null
      && resources.getLimits() != null
      && (quantity = resources.getLimits().get("cpu")) != null
      && quantity.getAmount() != null) {
    return KubernetesSize.toCores(quantity.getAmount());
  }
  return 0;
}
 
Example #25
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the RAM request in bytes, if it is present in given container otherwise 0 will be
 * returned.
 */
public static long getRamRequest(Container container) {
  final ResourceRequirements resources = container.getResources();
  final Quantity quantity;
  if (resources != null
      && resources.getRequests() != null
      && (quantity = resources.getRequests().get("memory")) != null
      && quantity.getAmount() != null) {
    return Quantity.getAmountInBytes(quantity).longValue();
  }
  return 0;
}
 
Example #26
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the RAM limit in bytes, if it is present in given container otherwise 0 will be
 * returned.
 */
public static long getRamLimit(Container container) {
  final ResourceRequirements resources = container.getResources();
  final Quantity quantity;
  if (resources != null
      && resources.getLimits() != null
      && (quantity = resources.getLimits().get("memory")) != null
      && quantity.getAmount() != null) {
    return Quantity.getAmountInBytes(quantity).longValue();
  }
  return 0;
}
 
Example #27
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public StatefulSetDiff testCpuResources(ResourceRequirements requirements1, ResourceRequirements requirements2) {
    StatefulSet ss1 = new StatefulSetBuilder()
            .withNewMetadata()
                .withNamespace("test")
                .withName("foo")
            .endMetadata()
            .withNewSpec().
                withNewTemplate()
                    .withNewSpec()
                        .addNewContainer()
                            .withResources(requirements1)
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec()
        .build();
    StatefulSet ss2 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
                .withNewTemplate()
                    .withNewSpec()
                        .addNewContainer()
                            .withResources(requirements2)
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec()
            .build();
    return new StatefulSetDiff(ss1, ss2);
}
 
Example #28
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 #29
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 #30
Source File: ContainersTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test(dataProvider = "k8sNotionRamLimitProvider")
public void testAddContainerRamLimitInK8sNotion(
    String ramLimit, String amount, String format, ResourceRequirements resources) {
  when(container.getResources()).thenReturn(resources);

  Containers.addRamLimit(container, ramLimit);

  verify(container).setResources(resourceCaptor.capture());
  ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("memory").getAmount(), amount);
  assertEquals(captured.getLimits().get("memory").getFormat(), format);
}