本文整理汇总了Java中io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ResourceRequirementsBuilder类的具体用法?Java ResourceRequirementsBuilder怎么用?Java ResourceRequirementsBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceRequirementsBuilder类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ResourceRequirementsBuilder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildResourceRequirements
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; //导入依赖的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();
}
示例2: createClaim
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; //导入依赖的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;
}
示例3: createPod
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; //导入依赖的package包/类
@VisibleForTesting
Pod createPod(RunSpec runSpec) {
final String podName = HYPE_RUN + "-" + randomAlphaNumeric(8);
final RunEnvironment env = runSpec.runEnvironment();
final List<Secret> secrets = env.secretMounts();
final StagedContinuation stagedContinuation = runSpec.stagedContinuation();
final List<VolumeMountInfo> volumeMountInfos = volumeMountInfos(env.volumeMounts());
final Pod basePod = getBasePod(env, runSpec.image());
// add metadata name
final ObjectMeta metadata = basePod.getMetadata() != null
? basePod.getMetadata()
: new ObjectMeta();
metadata.setName(podName);
basePod.setMetadata(metadata);
final PodSpec spec = basePod.getSpec();
// add volumes
secrets.forEach(s ->
spec.getVolumes()
.add(new VolumeBuilder()
.withName(s.name())
.withNewSecret()
.withSecretName(s.name())
.endSecret()
.build()));
volumeMountInfos.stream()
.map(VolumeMountInfo::volume)
.forEach(spec.getVolumes()::add);
final Container container = findHypeRunContainer(basePod);
// add volume mounts
secrets.forEach(s ->
container.getVolumeMounts()
.add(new VolumeMountBuilder()
.withName(s.name())
.withMountPath(s.mountPath())
.withReadOnly(true)
.build()));
volumeMountInfos.stream()
.map(VolumeMountInfo::volumeMount)
.forEach(container.getVolumeMounts()::add);
// set args
if (container.getArgs().size() > 0) {
LOG.warn("Overriding " + HYPE_RUN + " container args");
}
container.setArgs(singletonList(stagedContinuation.manifestPath().toUri().toString()));
// add env var
container.getEnv()
.add(new EnvVarBuilder()
.withName(EXECUTION_ID)
.withValue(podName)
.build());
// add resource requests
final ResourceRequirementsBuilder resourceReqsBuilder = container.getResources() != null
? new ResourceRequirementsBuilder(
container.getResources())
: new ResourceRequirementsBuilder();
for (Map.Entry<String, String> request : env.resourceRequests().entrySet()) {
resourceReqsBuilder.addToRequests(request.getKey(), new Quantity(request.getValue()));
}
container.setResources(resourceReqsBuilder.build());
return basePod;
}
示例4: createPod
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; //导入依赖的package包/类
@VisibleForTesting
static Pod createPod(WorkflowInstance workflowInstance, RunSpec runSpec, KubernetesSecretSpec secretSpec) {
final String imageWithTag = runSpec.imageName().contains(":")
? runSpec.imageName()
: runSpec.imageName() + ":latest";
final PodBuilder podBuilder = new PodBuilder()
.withNewMetadata()
.withName(runSpec.executionId())
.addToAnnotations(STYX_WORKFLOW_INSTANCE_ANNOTATION, workflowInstance.toKey())
.addToAnnotations(DOCKER_TERMINATION_LOGGING_ANNOTATION,
String.valueOf(runSpec.terminationLogging()))
.endMetadata();
final PodSpecBuilder specBuilder = new PodSpecBuilder()
.withRestartPolicy("Never");
final ResourceRequirementsBuilder resourceRequirements = new ResourceRequirementsBuilder();
runSpec.memRequest().ifPresent(s -> resourceRequirements.addToRequests("memory", new Quantity(s)));
runSpec.memLimit().ifPresent(s -> resourceRequirements.addToLimits("memory", new Quantity(s)));
final ContainerBuilder containerBuilder = new ContainerBuilder()
.withName(STYX_RUN)
.withImage(imageWithTag)
.withArgs(runSpec.args())
.withEnv(buildEnv(workflowInstance, runSpec))
.withResources(resourceRequirements.build());
secretSpec.serviceAccountSecret().ifPresent(serviceAccountSecret -> {
final SecretVolumeSource saVolumeSource = new SecretVolumeSourceBuilder()
.withSecretName(serviceAccountSecret)
.build();
final Volume saVolume = new VolumeBuilder()
.withName(STYX_WORKFLOW_SA_SECRET_NAME)
.withSecret(saVolumeSource)
.build();
specBuilder.addToVolumes(saVolume);
final VolumeMount saMount = new VolumeMountBuilder()
.withMountPath(STYX_WORKFLOW_SA_SECRET_MOUNT_PATH)
.withName(saVolume.getName())
.withReadOnly(true)
.build();
containerBuilder.addToVolumeMounts(saMount);
containerBuilder.addToEnv(envVar(STYX_WORKFLOW_SA_ENV_VARIABLE,
saMount.getMountPath() + STYX_WORKFLOW_SA_JSON_KEY));
});
secretSpec.customSecret().ifPresent(secret -> {
final SecretVolumeSource secretVolumeSource = new SecretVolumeSourceBuilder()
.withSecretName(secret.name())
.build();
final Volume secretVolume = new VolumeBuilder()
.withName(secret.name())
.withSecret(secretVolumeSource)
.build();
specBuilder.addToVolumes(secretVolume);
final VolumeMount secretMount = new VolumeMountBuilder()
.withMountPath(secret.mountPath())
.withName(secretVolume.getName())
.withReadOnly(true)
.build();
containerBuilder.addToVolumeMounts(secretMount);
});
specBuilder.addToContainers(containerBuilder.build());
podBuilder.withSpec(specBuilder.build());
return podBuilder.build();
}
示例5: buildResourceRequirements
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; //导入依赖的package包/类
private ResourceRequirements buildResourceRequirements() {
return new ResourceRequirementsBuilder()
.withLimits(getLimits())
.withRequests(getRequests())
.build();
}