本文整理汇总了Java中io.fabric8.kubernetes.api.model.Container类的典型用法代码示例。如果您正苦于以下问题:Java Container类的具体用法?Java Container怎么用?Java Container使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mountsSecretVolumeWhenLoadedFromYaml
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Test
public void mountsSecretVolumeWhenLoadedFromYaml() throws Exception {
RunEnvironment env = fromYaml("/minimal-pod.yaml")
.withSecret(SECRET);
Pod pod = createPod(env);
final PodSpec spec = pod.getSpec();
assertThat(spec.getVolumes(), hasItems(new VolumeBuilder()
.withName(SECRET.name())
.withNewSecret()
.withSecretName(SECRET.name())
.endSecret()
.build()));
Container container = findHypeRunContainer(pod);
assertThat(container.getVolumeMounts(), hasItems(new VolumeMountBuilder()
.withName(SECRET.name())
.withMountPath(SECRET.mountPath())
.withReadOnly(true)
.build()));
}
示例2: loadsFromYaml
import io.fabric8.kubernetes.api.model.Container; //导入依赖的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")));
}
示例3: matches
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Override
public boolean matches(Object object) {
if (object == null || !(object instanceof Deployment)) {
return false;
}
Deployment deployment = (Deployment)object;
ObjectMeta metadata = deployment.getMetadata();
DeploymentSpec spec = deployment.getSpec();
PodTemplateSpec podTemplateSpec = spec.getTemplate();
String podLabel = podTemplateSpec.getMetadata().getLabels().get("osc-deployment");
Container container = podTemplateSpec.getSpec().getContainers().get(0);
return this.name.equals(metadata.getName()) &&
this.name.equals(podLabel) &&
this.replicaCount == spec.getReplicas() &&
this.imageName.equals(container.getImage()) &&
this.name.equals(container.getName());
}
示例4: shouldEnableTerminationLoggingWhenTrue
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Test
public void shouldEnableTerminationLoggingWhenTrue() throws Exception {
Pod pod = KubernetesDockerRunner.createPod(
WORKFLOW_INSTANCE,
DockerRunner.RunSpec.builder()
.executionId("eid")
.imageName("busybox")
.terminationLogging(true)
.build(),
EMPTY_SECRET_SPEC);
Map<String, String> annotations = pod.getMetadata().getAnnotations();
assertThat(annotations.get(DOCKER_TERMINATION_LOGGING_ANNOTATION), is("true"));
List<Container> containers = pod.getSpec().getContainers();
Optional<EnvVar> terminationLogVar = containers.get(0).getEnv().stream()
.filter(e -> TERMINATION_LOG.equals(e.getName())).findAny();
assertThat(terminationLogVar.get().getValue(), is("/dev/termination-log"));
}
示例5: createInitContainer
import io.fabric8.kubernetes.api.model.Container; //导入依赖的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();
}
示例6: create
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Test
public void create() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.memory", "128Mi");
props.put("spring.cloud.deployer.kubernetes.environmentVariables",
"JAVA_OPTIONS=-Xmx64m,KUBERNETES_NAMESPACE=test-space");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
Container container = defaultContainerFactory.create("app-test",
appDeploymentRequest, null, null, false);
assertNotNull(container);
assertEquals(3, container.getEnv().size());
EnvVar envVar1 = container.getEnv().get(0);
EnvVar envVar2 = container.getEnv().get(1);
assertEquals("JAVA_OPTIONS", envVar1.getName());
assertEquals("-Xmx64m", envVar1.getValue());
assertEquals("KUBERNETES_NAMESPACE", envVar2.getName());
assertEquals("test-space", envVar2.getValue());
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:27,代码来源:DefaultContainerFactoryTests.java
示例7: createWithContainerCommand
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Test
public void createWithContainerCommand() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerCommand",
"echo arg1 'arg2'");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
Container container = defaultContainerFactory.create("app-test",
appDeploymentRequest, null, null, false);
assertNotNull(container);
assertThat(container.getCommand()).containsExactly("echo", "arg1", "arg2");
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:20,代码来源:DefaultContainerFactoryTests.java
示例8: createWithPorts
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Test
public void createWithPorts() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerPorts",
"8081, 8082, 65535");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
Container container = defaultContainerFactory.create("app-test",
appDeploymentRequest, null, null, false);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("There should be three ports set", containerPorts.size() == 3);
assertTrue(8081 == containerPorts.get(0).getContainerPort());
assertTrue(8082 == containerPorts.get(1).getContainerPort());
assertTrue(65535 == containerPorts.get(2).getContainerPort());
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:25,代码来源:DefaultContainerFactoryTests.java
示例9: addMissingResources
import io.fabric8.kubernetes.api.model.Container; //导入依赖的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);
}
示例10: newPod
import io.fabric8.kubernetes.api.model.Container; //导入依赖的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();
}
示例11: provision
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Override
public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity)
throws InfrastructureException {
final String workspaceId = identity.getWorkspaceId();
final Set<String> subPaths = new HashSet<>();
final PersistentVolumeClaim pvc = newPVC(pvcName, pvcAccessMode, pvcQuantity);
osEnv.getPersistentVolumeClaims().put(pvcName, pvc);
for (Pod pod : osEnv.getPods().values()) {
PodSpec podSpec = pod.getSpec();
for (Container container : podSpec.getContainers()) {
String machineName = Names.machineName(pod, container);
InternalMachineConfig machineConfig = osEnv.getMachines().get(machineName);
addMachineVolumes(workspaceId, subPaths, podSpec, container, machineConfig);
}
}
if (preCreateDirs && !subPaths.isEmpty()) {
pvc.setAdditionalProperty(
format(SUBPATHS_PROPERTY_FMT, workspaceId),
subPaths.toArray(new String[subPaths.size()]));
}
}
示例12: addMachineVolumes
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
private void addMachineVolumes(
String workspaceId,
Set<String> subPaths,
PodSpec podSpec,
Container container,
InternalMachineConfig machineConfig) {
if (machineConfig.getVolumes().isEmpty()) {
return;
}
for (Entry<String, Volume> volumeEntry : machineConfig.getVolumes().entrySet()) {
String volumePath = volumeEntry.getValue().getPath();
String subPath = getVolumeSubPath(workspaceId, volumeEntry.getKey());
subPaths.add(subPath);
container.getVolumeMounts().add(newVolumeMount(pvcName, volumePath, subPath));
addVolumeIfNeeded(podSpec);
}
}
示例13: addMachineVolumes
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
private void addMachineVolumes(
String workspaceId,
Map<String, PersistentVolumeClaim> claims,
PodSpec podSpec,
Container container,
InternalMachineConfig machineConfig) {
if (machineConfig.getVolumes().isEmpty()) {
return;
}
for (Entry<String, Volume> volumeEntry : machineConfig.getVolumes().entrySet()) {
String volumeName = volumeEntry.getKey();
String volumePath = volumeEntry.getValue().getPath();
String subPath = workspaceId + '/' + volumeName;
String pvcUniqueName = pvcNamePrefix + '-' + workspaceId + '-' + volumeName;
PersistentVolumeClaim newPVC = newPVC(pvcUniqueName, pvcAccessMode, pvcQuantity);
putLabel(newPVC, CHE_WORKSPACE_ID_LABEL, workspaceId);
claims.put(pvcUniqueName, newPVC);
container.getVolumeMounts().add(newVolumeMount(pvcUniqueName, volumePath, subPath));
addVolumeIfAbsent(podSpec, pvcUniqueName);
}
}
示例14: provision
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Override
public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity)
throws InfrastructureException {
for (Pod pod : osEnv.getPods().values()) {
for (Container container : pod.getSpec().getContainers()) {
String machineName = Names.machineName(pod, container);
InternalMachineConfig machineConf = osEnv.getMachines().get(machineName);
machineConf
.getEnv()
.forEach(
(key, value) -> {
container.getEnv().removeIf(env -> key.equals(env.getName()));
container.getEnv().add(new EnvVar(key, value, null));
});
}
}
}
示例15: provision
import io.fabric8.kubernetes.api.model.Container; //导入依赖的package包/类
@Override
public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity)
throws InfrastructureException {
for (Pod podConfig : osEnv.getPods().values()) {
final PodSpec podSpec = podConfig.getSpec();
for (Container containerConfig : podSpec.getContainers()) {
String machineName = Names.machineName(podConfig, containerConfig);
InternalMachineConfig machineConfig = osEnv.getMachines().get(machineName);
if (!machineConfig.getServers().isEmpty()) {
ServerExposer serverExposer =
new ServerExposer(machineName, podConfig, containerConfig, osEnv);
serverExposer.expose(machineConfig.getServers());
}
}
}
}