当前位置: 首页>>代码示例>>Java>>正文


Java ResourceRequirements类代码示例

本文整理汇总了Java中io.fabric8.kubernetes.api.model.ResourceRequirements的典型用法代码示例。如果您正苦于以下问题:Java ResourceRequirements类的具体用法?Java ResourceRequirements怎么用?Java ResourceRequirements使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceRequirements类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ResourceRequirements类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadsFromYaml

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void loadsFromYaml() throws Exception {
  RunEnvironment env = fromYaml("/minimal-pod.yaml");
  Pod pod = createPod(env);

  assertThat(pod.getSpec().getRestartPolicy(), is("Never"));

  Container container = findHypeRunContainer(pod);
  assertThat(container.getImage(), is("busybox:1"));
  assertThat(container.getImagePullPolicy(), is("Always"));
  assertThat(container.getEnv(), hasItems(envVar("EXAMPLE", "my-env-value")));

  ResourceRequirements resources = container.getResources();
  assertThat(resources.getRequests(), hasEntry("cpu", new Quantity("100m")));
  assertThat(resources.getLimits(), hasEntry("memory", new Quantity("1Gi")));
}
 
开发者ID:spotify,项目名称:hype,代码行数:17,代码来源:KubernetesDockerRunnerTest.java

示例2: shouldConfigureResourceRequirements

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void shouldConfigureResourceRequirements() throws IOException, IsClosedException {
  final String memRequest = "17Mi";
  final String memLimit = "4711Mi";
  final Pod pod = KubernetesDockerRunner.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)));
}
 
开发者ID:spotify,项目名称:styx,代码行数:17,代码来源:KubernetesDockerRunnerTest.java

示例3: buildResourceRequirements

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
static ResourceRequirements buildResourceRequirements(String serviceName, DeploymentEnvironment deploymentEnvironment) {
  Map<String, Map> customSizing = deploymentEnvironment.getCustomSizing().get(serviceName);

  if (customSizing == null) {
    return null;
  }

  ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder();
  if (customSizing.get("requests") != null) {
    resourceRequirementsBuilder.addToRequests("memory", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("requests").get("memory"))).build());
    resourceRequirementsBuilder.addToRequests("cpu", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("requests").get("cpu"))).build());
  }
  if (customSizing.get("limits") != null) {
    resourceRequirementsBuilder.addToLimits("memory", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("limits").get("memory"))).build());
    resourceRequirementsBuilder.addToLimits("cpu", new QuantityBuilder().withAmount(CustomSizing.stringOrNull(customSizing.get("limits").get("cpu"))).build());
  }

  return resourceRequirementsBuilder.build();
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:20,代码来源:ResourceBuilder.java

示例4: addMissingResources

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Override
public void addMissingResources(KubernetesListBuilder builder) {
    log.info("addMissingResources");

    List<HasMetadata> items = builder.getItems();
    for (HasMetadata item : items) {
        if (item instanceof Deployment) {
            Deployment deployment = (Deployment)item;
            List<Container> containers = getCandidateContainers(deployment);
            for (Container container : containers) {
                if (container.getResources() == null) {
                    ResourceRequirements resourceRequirements = buildResourceRequirements();

                    log.info(describe(resourceRequirements));

                    container.setResources(resourceRequirements);
                }
            }
        }
    }

    builder.withItems(items);
}
 
开发者ID:garethahealy,项目名称:kube-dsl-defaults,代码行数:24,代码来源:LimitEnricher.java

示例5: mockPod

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
private static Pod mockPod(String machineName, long ramLimit) {
  final String containerName = "container_" + machineName;
  final Container containerMock = mock(Container.class);
  final ResourceRequirements resourcesMock = mock(ResourceRequirements.class);
  final Quantity quantityMock = mock(Quantity.class);
  final Pod podMock = mock(Pod.class);
  final PodSpec specMock = mock(PodSpec.class);
  final ObjectMeta metadataMock = mock(ObjectMeta.class);
  when(podMock.getSpec()).thenReturn(specMock);
  when(podMock.getMetadata()).thenReturn(metadataMock);
  when(quantityMock.getAmount()).thenReturn(String.valueOf(ramLimit));
  when(resourcesMock.getLimits()).thenReturn(ImmutableMap.of("memory", quantityMock));
  when(containerMock.getName()).thenReturn(containerName);
  when(containerMock.getResources()).thenReturn(resourcesMock);
  when(metadataMock.getAnnotations())
      .thenReturn(
          ImmutableMap.of(format(MACHINE_NAME_ANNOTATION_FMT, containerName), machineName));
  when(specMock.getContainers()).thenReturn(ImmutableList.of(containerMock));
  return podMock;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:OpenShiftEnvironmentFactoryTest.java

示例6: createClaim

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
private PersistentVolumeClaim createClaim(VolumeRequest volumeRequest) {
  final ClaimRequest spec = volumeRequest.spec();

  if (spec.useExisting()) {
    final String claimName = volumeRequest.id();
    final PersistentVolumeClaim existingClaim =
        client.persistentVolumeClaims().withName(claimName).get();

    if (existingClaim != null) {
      return existingClaim;
    }
  }

  final ResourceRequirements resources = new ResourceRequirementsBuilder()
      .addToRequests("storage", new Quantity(spec.size()))
      .build();

  final PersistentVolumeClaim claimTemplate = new PersistentVolumeClaimBuilder()
      .withNewMetadata()
      .withName(volumeRequest.id())
      .addToAnnotations(STORAGE_CLASS_ANNOTATION, spec.storageClass())
      .endMetadata()
      .withNewSpec()
      // todo: storageClassName: <class> // in 1.6
      .withAccessModes(READ_WRITE_ONCE, READ_ONLY_MANY)
      .withResources(resources)
      .endSpec()
      .build();

  final PersistentVolumeClaim claim = client.persistentVolumeClaims().create(claimTemplate);
  LOG.info("Created PersistentVolumeClaim {} for {}",
      claim.getMetadata().getName(),
      volumeRequest);

  return claim;
}
 
开发者ID:spotify,项目名称:hype,代码行数:37,代码来源:VolumeRepository.java

示例7: setsResourceRequests

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void setsResourceRequests() throws Exception {
  RunEnvironment env = environment()
      .withRequest(CPU.of("250m"))
      .withRequest(MEMORY.of("2Gi"))
      .withRequest("gpu", "2");
  Pod pod = createPod(env);

  Container container = findHypeRunContainer(pod);
  ResourceRequirements resources = container.getResources();
  assertThat(resources.getRequests(), hasEntry("cpu", new Quantity("250m")));
  assertThat(resources.getRequests(), hasEntry("memory", new Quantity("2Gi")));
  assertThat(resources.getRequests(), hasEntry("gpu", new Quantity("2")));
}
 
开发者ID:spotify,项目名称:hype,代码行数:15,代码来源:KubernetesDockerRunnerTest.java

示例8: addsResourceRequestsWhenLoadedFromYaml

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void addsResourceRequestsWhenLoadedFromYaml() throws Exception {
  RunEnvironment env = fromYaml("/minimal-pod.yaml")
      .withRequest(MEMORY.of("2Gi"))
      .withRequest("gpu", "2");
  Pod pod = createPod(env);

  Container container = findHypeRunContainer(pod);
  ResourceRequirements resources = container.getResources();
  assertThat(resources.getRequests(), hasEntry("cpu", new Quantity("100m")));
  assertThat(resources.getRequests(), hasEntry("memory", new Quantity("2Gi")));
  assertThat(resources.getRequests(), hasEntry("gpu", new Quantity("2")));
}
 
开发者ID:spotify,项目名称:hype,代码行数:14,代码来源:KubernetesDockerRunnerTest.java

示例9: overridesResourceRequestsWhenLoadedFromYaml

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void overridesResourceRequestsWhenLoadedFromYaml() throws Exception {
  RunEnvironment env = fromYaml("/minimal-pod.yaml")
      .withRequest(CPU.of("250m"));
  Pod pod = createPod(env);

  Container container = findHypeRunContainer(pod);
  ResourceRequirements resources = container.getResources();
  assertThat(resources.getRequests(), hasEntry("cpu", new Quantity("250m")));
}
 
开发者ID:spotify,项目名称:hype,代码行数:11,代码来源:KubernetesDockerRunnerTest.java

示例10: getRamLimit

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
/**
 * 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 KubernetesSize.toBytes(quantity.getAmount());
  }
  return 0;
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:Containers.java

示例11: testProvisionRamLimitAttributeToContainer

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void testProvisionRamLimitAttributeToContainer() throws Exception {
  ramLimitProvisioner.provision(osEnv, identity);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("memory").getAmount(), RAM_LIMIT_ATTRIBUTE);
}
 
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:RamLimitProvisionerTest.java

示例12: testOverridesContainerRamLimitFromMachineAttribute

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void testOverridesContainerRamLimitFromMachineAttribute() throws Exception {
  final ResourceRequirements containerResource = mock(ResourceRequirements.class);
  final HashMap<String, Quantity> limits = new HashMap<>();
  limits.put("memory", new Quantity("3221225472"));
  when(containerResource.getLimits()).thenReturn(limits);
  when(container.getResources()).thenReturn(containerResource);

  ramLimitProvisioner.provision(osEnv, identity);

  verify(container).setResources(resourceCaptor.capture());
  final ResourceRequirements captured = resourceCaptor.getValue();
  assertEquals(captured.getLimits().get("memory").getAmount(), RAM_LIMIT_ATTRIBUTE);
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:RamLimitProvisionerTest.java

示例13: testAddContainerRamLimitWhenResourceIsNull

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void testAddContainerRamLimitWhenResourceIsNull() throws Exception {
  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));
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:ContainersTest.java

示例14: testAddContainerRamLimitWhenResourceDoesNotContainAnyLimits

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
@Test
public void testAddContainerRamLimitWhenResourceDoesNotContainAnyLimits() throws Exception {
  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));
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:ContainersTest.java

示例15: createPodSpec

import io.fabric8.kubernetes.api.model.ResourceRequirements; //导入依赖的package包/类
/**
 * Create a PodSpec to be used for app and task deployments
 *
 * @param appId the app ID
 * @param request app deployment request
 * @param port port to use for app or null if none
 * @param neverRestart use restart policy of Never
 * @return the PodSpec
 */
protected PodSpec createPodSpec(String appId, AppDeploymentRequest request, Integer port,
	boolean neverRestart) {
	PodSpecBuilder podSpec = new PodSpecBuilder();

	// Add image secrets if set
	if (properties.getImagePullSecret() != null) {
		podSpec.addNewImagePullSecret(properties.getImagePullSecret());
	}

	boolean hostNetwork = getHostNetwork(request);
	Container container = containerFactory.create(appId, request, port, hostNetwork);

	// add memory and cpu resource limits
	ResourceRequirements req = new ResourceRequirements();
	req.setLimits(deduceResourceLimits(request));
	req.setRequests(deduceResourceRequests(request));
	container.setResources(req);
	ImagePullPolicy pullPolicy = deduceImagePullPolicy(request);
	container.setImagePullPolicy(pullPolicy.name());

	//
	Map<String, String> nodeSelectors = getNodeSelectors(request.getDeploymentProperties());
	if (nodeSelectors.size() > 0) {
		podSpec.withNodeSelector(nodeSelectors);
	}
	// only add volumes with corresponding volume mounts
	podSpec.withVolumes(getVolumes(request).stream()
			.filter(volume -> container.getVolumeMounts().stream()
					.anyMatch(volumeMount -> volumeMount.getName().equals(volume.getName())))
			.collect(Collectors.toList()));

	if (hostNetwork) {
		podSpec.withHostNetwork(true);
	}
	podSpec.addToContainers(container);

	if (neverRestart){
		podSpec.withRestartPolicy("Never");
	}

	return podSpec.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:52,代码来源:AbstractKubernetesDeployer.java


注:本文中的io.fabric8.kubernetes.api.model.ResourceRequirements类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。