本文整理汇总了Java中io.fabric8.kubernetes.api.model.PodSpecBuilder类的典型用法代码示例。如果您正苦于以下问题:Java PodSpecBuilder类的具体用法?Java PodSpecBuilder怎么用?Java PodSpecBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PodSpecBuilder类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了PodSpecBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: build
import io.fabric8.kubernetes.api.model.PodSpecBuilder; //导入依赖的package包/类
@Override
public Pod build() {
PodSpecBuilder specBuilder = new PodSpecBuilder();
specBuilder.withContainers(containerBuilders.stream().map(ContainerBuilder::build).collect(Collectors.toList()));
specBuilder.withDnsPolicy("ClusterFirst");
if (!nodeSelectorLabels.isEmpty()) {
specBuilder.withNodeSelector(nodeSelectorLabels);
}
specBuilder.withRestartPolicy("Always");
if (StringUtils.isNotBlank(serviceAccount)) {
specBuilder.withServiceAccount(serviceAccount);
}
if (gracefulShutdown >= 0) {
specBuilder.withTerminationGracePeriodSeconds((long) gracefulShutdown);
}
specBuilder.withVolumes(volumes.stream().map(Volume::build).collect(Collectors.toList()));
if (runAsUser != null) {
specBuilder.withNewSecurityContext()
.withRunAsUser(runAsUser)
.endSecurityContext();
}
return new io.fabric8.kubernetes.api.model.PodBuilder()
.withMetadata(metadataBuilder().build())
.withSpec(specBuilder.build())
.build();
}
开发者ID:xtf-cz,项目名称:xtf,代码行数:35,代码来源:PodBuilder.java
示例2: createPod
import io.fabric8.kubernetes.api.model.PodSpecBuilder; //导入依赖的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();
}
开发者ID:spotify,项目名称:styx,代码行数:72,代码来源:KubernetesDockerRunner.java
示例3: createPodSpec
import io.fabric8.kubernetes.api.model.PodSpecBuilder; //导入依赖的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
示例4: newPod
import io.fabric8.kubernetes.api.model.PodSpecBuilder; //导入依赖的package包/类
private static Pod newPod(String podName, String restartPolicy, Container... containers) {
final ObjectMeta podMetadata = new ObjectMetaBuilder().withName(podName).build();
final PodSpec podSpec =
new PodSpecBuilder().withRestartPolicy(restartPolicy).withContainers(containers).build();
return new PodBuilder().withMetadata(podMetadata).withSpec(podSpec).build();
}
开发者ID:eclipse,项目名称:che,代码行数:7,代码来源:RestartPolicyRewriterTest.java
注:本文中的io.fabric8.kubernetes.api.model.PodSpecBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论