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


Java ContainerBuilder类代码示例

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


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

示例1: createInitContainer

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
/**
 * For StatefulSets, create an init container to parse ${HOSTNAME} to get the `instance.index` and write it to
 * config/application.properties on a shared volume so the main container has it. Using the legacy annotation
 * configuration since the current client version does not directly support InitContainers.
 *
 * Since 1.8 the annotation method has been removed, and the initContainer API is supported since 1.6
 *
 * @return a container definition with the above mentioned configuration
 */
private Container createInitContainer() {
	List<String> command = new LinkedList<>();

	String commandString = String
			.format("%s && %s", setIndexProperty("INSTANCE_INDEX"), setIndexProperty("spring.application.index"));

	command.add("sh");
	command.add("-c");
	command.add(commandString);
	return new ContainerBuilder().withName("index-provider")
			.withImage("busybox")
			.withImagePullPolicy("IfNotPresent")
			.withCommand(command)
			.withVolumeMounts(new VolumeMountBuilder().withName("config").withMountPath("/config").build())
			.build();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:26,代码来源:KubernetesAppDeployer.java

示例2: newPod

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
/** Returns new instance of {@link Pod} with given name and command. */
private Pod newPod(String podName, String[] command) {
  final Container container =
      new ContainerBuilder()
          .withName(podName)
          .withImage(jobImage)
          .withImagePullPolicy(IMAGE_PULL_POLICY)
          .withCommand(command)
          .withVolumeMounts(newVolumeMount(pvcName, JOB_MOUNT_PATH, null))
          .withNewResources()
          .withLimits(singletonMap("memory", new Quantity(jobMemoryLimit)))
          .endResources()
          .build();
  return new PodBuilder()
      .withNewMetadata()
      .withName(podName)
      .endMetadata()
      .withNewSpec()
      .withContainers(container)
      .withVolumes(newVolume(pvcName, pvcName))
      .withRestartPolicy(POD_RESTART_POLICY)
      .endSpec()
      .build();
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:PVCSubPathHelper.java

示例3: setUp

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
  container = new ContainerBuilder().withName("main").build();
  Pod pod =
      new PodBuilder()
          .withNewMetadata()
          .withName("pod")
          .endMetadata()
          .withNewSpec()
          .withContainers(container)
          .endSpec()
          .build();

  openShiftEnvironment =
      OpenShiftEnvironment.builder().setPods(ImmutableMap.of("pod", pod)).build();
  this.serverExposer = new ServerExposer(MACHINE_NAME, pod, container, openShiftEnvironment);
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ServerExposerTest.java

示例4: setup

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
@BeforeMethod
public void setup() throws Exception {
  converter = new DockerImageEnvironmentConverter();
  when(recipe.getContent()).thenReturn(RECIPE_CONTENT);
  when(recipe.getType()).thenReturn(RECIPE_TYPE);
  machines = ImmutableMap.of(MACHINE_NAME, mock(InternalMachineConfig.class));
  final Map<String, String> annotations = new HashMap<>();
  annotations.put(format(MACHINE_NAME_ANNOTATION_FMT, CONTAINER_NAME), MACHINE_NAME);
  pod =
      new PodBuilder()
          .withNewMetadata()
          .withName(POD_NAME)
          .withAnnotations(annotations)
          .endMetadata()
          .withNewSpec()
          .withContainers(
              new ContainerBuilder().withImage(RECIPE_CONTENT).withName(CONTAINER_NAME).build())
          .endSpec()
          .build();
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:DockerImageEnvironmentConverterTest.java

示例5: configureCloud

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
@Before
public void configureCloud() throws Exception {
    client = setupCloud(this).connect();
    deletePods(client, getLabels(this), false);

    String image = "busybox";
    Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image)
            .withCommand("cat").withTty(true).build();
    String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789");
    pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName).withLabels(getLabels(this))
            .endMetadata().withNewSpec().withContainers(c).endSpec().build());

    System.out.println("Created pod: " + pod.getMetadata().getName());

    decorator = new ContainerExecDecorator(client, pod.getMetadata().getName(), image, client.getNamespace());
}
 
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:17,代码来源:ContainerExecDecoratorTest.java

示例6: build

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
public ResourceDeployment build() {
    ArrayList<Container> containers = new ArrayList<>();

    pod.getContainers().forEach(e -> {
        Container container = new ContainerBuilder()
            .withImage(e.getDockerImageTag().get())
            .withName(e.getCleanStackName())
            .addAllToPorts(e.getOpenPorts().stream().map(Port::toContainerPort).collect(Collectors.toList()))
            .build();
        
        containers.add(container);
    });

    deployment = new DeploymentBuilder()
        .withNewMetadata()
        .withName(name + "-deployment")
        .addToLabels("app", name)
        .endMetadata()
        .withNewSpec()
        .withNewSelector()
        .addToMatchLabels("app", name)
        .endSelector()
        .withNewTemplate()
        .withNewMetadata()
        .withName(name)
        .addToLabels("app", name)
        .endMetadata()
        .withNewSpec()
        .addAllToContainers(containers)
        .endSpec()
        .endTemplate()
        .endSpec().build();
    return this;
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:35,代码来源:ResourceDeployment.java

示例7: convert

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
public OpenShiftEnvironment convert(DockerImageEnvironment environment)
    throws InfrastructureException {
  final Iterator<String> iterator = environment.getMachines().keySet().iterator();
  if (!iterator.hasNext()) {
    throw new InternalInfrastructureException(
        "DockerImage environment must contain at least one machine configuration");
  }
  final String machineName = iterator.next();
  final String dockerImage = environment.getRecipe().getContent();
  final Map<String, String> annotations = new HashMap<>();
  annotations.put(format(MACHINE_NAME_ANNOTATION_FMT, CONTAINER_NAME), machineName);

  final Pod pod =
      new PodBuilder()
          .withNewMetadata()
          .withName(POD_NAME)
          .withAnnotations(annotations)
          .endMetadata()
          .withNewSpec()
          .withContainers(
              new ContainerBuilder().withImage(dockerImage).withName(CONTAINER_NAME).build())
          .endSpec()
          .build();
  return OpenShiftEnvironment.builder()
      .setMachines(environment.getMachines())
      .setInternalRecipe(environment.getRecipe())
      .setWarnings(environment.getWarnings())
      .setPods(ImmutableMap.of(POD_NAME, pod))
      .build();
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:DockerImageEnvironmentConverter.java

示例8: getPodTemplate

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
@NotNull
@Override
public Pod getPodTemplate(@NotNull CloudInstanceUserData cloudInstanceUserData, @NotNull KubeCloudImage kubeCloudImage, @NotNull KubeCloudClientParameters clientParameters) {
    String agentNameProvided = cloudInstanceUserData.getAgentName();
    final String agentName = StringUtil.isEmpty(agentNameProvided) ? UUID.randomUUID().toString() : agentNameProvided;

    ImagePullPolicy imagePullPolicy = kubeCloudImage.getImagePullPolicy();
    String serverAddress = cloudInstanceUserData.getServerAddress();
    String serverUUID = myServerSettings.getServerUUID();
    String cloudProfileId = cloudInstanceUserData.getProfileId();

    ContainerBuilder containerBuilder = new ContainerBuilder()
            .withName(agentName)
            .withImage(kubeCloudImage.getDockerImage())
            .withImagePullPolicy(imagePullPolicy == null ? ImagePullPolicy.IfNotPresent.getName() : imagePullPolicy.getName())
            .withEnv(new EnvVar(KubeContainerEnvironment.AGENT_NAME, agentName, null),
                     new EnvVar(KubeContainerEnvironment.SERVER_URL, serverAddress, null),
                     new EnvVar(KubeContainerEnvironment.SERVER_UUID, serverUUID, null),
                     new EnvVar(KubeContainerEnvironment.OFFICIAL_IMAGE_SERVER_URL, serverAddress, null),
                     new EnvVar(KubeContainerEnvironment.IMAGE_ID, kubeCloudImage.getId(), null),
                     new EnvVar(KubeContainerEnvironment.PROFILE_ID, cloudProfileId, null),
                     new EnvVar(KubeContainerEnvironment.INSTANCE_NAME, agentName, null));
    String dockerCommand = kubeCloudImage.getDockerCommand();
    if(!StringUtil.isEmpty(dockerCommand)) containerBuilder = containerBuilder.withCommand(dockerCommand);
    String dockerArguments = kubeCloudImage.getDockerArguments();
    if(!StringUtil.isEmpty(dockerArguments)) containerBuilder = containerBuilder.withArgs(dockerArguments);

    return new PodBuilder()
            .withNewMetadata()
            .withName(agentName)
            .withNamespace(clientParameters.getNamespace())
            .withLabels(CollectionsUtil.asMap(
                    KubeTeamCityLabels.TEAMCITY_AGENT_LABEL, "",
                    KubeTeamCityLabels.TEAMCITY_SERVER_UUID, serverUUID,
                    KubeTeamCityLabels.TEAMCITY_CLOUD_PROFILE, cloudProfileId,
                    KubeTeamCityLabels.TEAMCITY_CLOUD_IMAGE, kubeCloudImage.getId()))
            .endMetadata()
            .withNewSpec()
            .withContainers(Collections.singletonList(containerBuilder.build()))
            .withRestartPolicy(KubeApiConnector.NEVER_RESTART_POLICY)
            .endSpec()
            .build();
}
 
开发者ID:JetBrains,项目名称:teamcity-kubernetes-plugin,代码行数:44,代码来源:SimpleRunContainerBuildAgentPodTemplateProvider.java

示例9: createPod

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的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

示例10: createContainer

import io.fabric8.kubernetes.api.model.ContainerBuilder; //导入依赖的package包/类
private Container createContainer(String name) {
  return new ContainerBuilder().withName(name).build();
}
 
开发者ID:eclipse,项目名称:che,代码行数:4,代码来源:OpenShiftEnvironmentValidatorTest.java


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