本文整理汇总了Java中io.fabric8.kubernetes.api.model.PodSpec类的典型用法代码示例。如果您正苦于以下问题:Java PodSpec类的具体用法?Java PodSpec怎么用?Java PodSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PodSpec类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了PodSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mountsSecretVolumeWhenLoadedFromYaml
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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: newPod
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
private Pod newPod(String uid, String namespace, String name, String node) {
Pod pod = new Pod();
ObjectMeta objMeta = new ObjectMeta();
objMeta.setName(name);
objMeta.setNamespace(namespace);
objMeta.setUid(uid);
PodSpec spec = new PodSpec();
spec.setNodeName(node);
pod.setMetadata(objMeta);
pod.setSpec(spec);
return pod;
}
示例3: deployWithEnvironmentWithCommaDelimitedValue
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
@Test
public void deployWithEnvironmentWithCommaDelimitedValue() throws Exception {
AppDefinition definition = new AppDefinition("app-test", null);
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.environmentVariables",
"foo='bar,baz',car=caz,boo='zoo,gnu',doo=dar");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
PodSpec podSpec = deployer.createPodSpec("1", appDeploymentRequest, 8080, false);
assertThat(podSpec.getContainers().get(0).getEnv())
.contains(
new EnvVar("foo", "bar,baz", null),
new EnvVar("car", "caz", null),
new EnvVar("boo", "zoo,gnu", null),
new EnvVar("doo", "dar", null));
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:20,代码来源:KubernetesAppDeployerTests.java
示例4: provision
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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()]));
}
}
示例5: addMachineVolumes
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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);
}
}
示例6: addMachineVolumes
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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);
}
}
示例7: provision
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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());
}
}
}
}
示例8: mockPod
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的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;
}
示例9: updatePod
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
public String updatePod(final @NotNull String podId, final Pod pod) throws Exception {
// TODO needs implementing remotely!
return NodeHelper.excludeFromProcessMonitor(processMonitor, pod, new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("Updating pod " + pod);
PodSpec desiredState = pod.getSpec();
Objects.notNull(desiredState, "desiredState");
PodStatus currentState = NodeHelper.getOrCreatetStatus(pod);
List<Container> containers = KubernetesHelper.getContainers(pod);
model.updatePod(podId, pod);
return NodeHelper.createMissingContainers(processManager, model, pod, currentState, containers);
}
});
}
示例10: createPodSpec
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
private PodSpec createPodSpec() throws IOException {
PodSpec podSpec = new PodSpec();
podSpec.setHostname("localhost");
Container container = new Container();
container.setImage("docker.io/wildflyext/wildfly-camel:latest");
container.setName("wildfly-camel-test");
ContainerPort port = new ContainerPort();
port.setHostIP("0.0.0.0");
port.setContainerPort(8080);
List<ContainerPort> ports = new ArrayList<>();
ports.add(port);
container.setPorts(ports);
List<Container> containers = new ArrayList<>();
containers.add(container);
podSpec.setContainers(containers);
return podSpec;
}
示例11: mountsSecretVolume
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
@Test
public void mountsSecretVolume() throws Exception {
RunEnvironment env = environment()
.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()));
}
示例12: createDeploymentSpec
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
protected DeploymentSpec createDeploymentSpec(final Map<String, String> labels,
final String serviceAccountName,
final String imageName,
final ImagePullPolicy imagePullPolicy,
final String namespace,
final boolean hostNetwork,
final boolean tls,
final boolean verifyTls) {
final DeploymentSpec deploymentSpec = new DeploymentSpec();
final PodTemplateSpec podTemplateSpec = new PodTemplateSpec();
final ObjectMeta metadata = new ObjectMeta();
metadata.setLabels(normalizeLabels(labels));
podTemplateSpec.setMetadata(metadata);
final PodSpec podSpec = new PodSpec();
podSpec.setServiceAccountName(normalizeServiceAccountName(serviceAccountName));
podSpec.setContainers(Arrays.asList(this.createContainer(imageName, imagePullPolicy, namespace, tls, verifyTls)));
podSpec.setHostNetwork(Boolean.valueOf(hostNetwork));
final Map<String, String> nodeSelector = new HashMap<>();
nodeSelector.put("beta.kubernetes.io/os", "linux");
podSpec.setNodeSelector(nodeSelector);
if (tls) {
final Volume volume = new Volume();
volume.setName(DEFAULT_NAME + "-certs");
final SecretVolumeSource secretVolumeSource = new SecretVolumeSource();
secretVolumeSource.setSecretName(SECRET_NAME);
volume.setSecret(secretVolumeSource);
podSpec.setVolumes(Arrays.asList(volume));
}
podTemplateSpec.setSpec(podSpec);
deploymentSpec.setTemplate(podTemplateSpec);
return deploymentSpec;
}
示例13: newDeployment
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
private Deployment newDeployment(String uid, String namespace, String name, int desiredReplicaCount, String containerImageName) {
Deployment deployment = new Deployment();
ObjectMeta objMeta = new ObjectMeta();
objMeta.setName(name);
objMeta.setNamespace(namespace);
objMeta.setUid(uid);
DeploymentSpec spec = new DeploymentSpec();
spec.setReplicas(desiredReplicaCount);
Container container = new Container();
container.setImage(containerImageName);
PodSpec podSpec = new PodSpec();
podSpec.setContainers(Arrays.asList(container));
PodTemplateSpec podTemplateSpec = new PodTemplateSpec();
podTemplateSpec.setSpec(podSpec);
spec.setTemplate(podTemplateSpec);
deployment.setMetadata(objMeta);
deployment.setSpec(spec);
DeploymentStatus deploymentStatus = new DeploymentStatus();
deploymentStatus.setAvailableReplicas(3);
deployment.setStatus(deploymentStatus);
return deployment;
}
示例14: testGetStartedTime
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
@Test
public void testGetStartedTime() throws Exception {
KubeCloudImage image = m.mock(KubeCloudImage.class);
ObjectMeta metadata = new ObjectMeta();
metadata.setName("foo");
Pod pod = new Pod("1.0", "kind", metadata, new PodSpec(), new PodStatusBuilder().withStartTime("2017-06-12T22:59Z").build());
m.checking(new Expectations(){{
allowing(myApi).getPodStatus(with("foo")); will(returnValue(pod.getStatus()));
}});
KubeCloudInstanceImpl instance = new KubeCloudInstanceImpl(image, pod, myApi);
Date startedTime = instance.getStartedTime();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
assertEquals("2017-06-12T22:59Z", dateFormat.format(startedTime));
}
示例15: podsAsTable
import io.fabric8.kubernetes.api.model.PodSpec; //导入依赖的package包/类
protected TablePrinter podsAsTable(PodList pods) {
TablePrinter table = new TablePrinter();
table.columns("id", "image(s)", "host", "labels", "status");
List<Pod> items = pods.getItems();
if (items == null) {
items = Collections.EMPTY_LIST;
}
Filter<Pod> filter = KubernetesHelper.createPodFilter(filterText.getValue());
for (Pod item : items) {
if (filter.matches(item)) {
String id = KubernetesHelper.getName(item);
PodStatus podStatus = item.getStatus();
String status = "";
String host = "";
if (podStatus != null) {
status = KubernetesHelper.getStatusText(podStatus);
host = podStatus.getHostIP();
}
Map<String, String> labelMap = item.getMetadata().getLabels();
String labels = KubernetesHelper.toLabelsString(labelMap);
PodSpec spec = item.getSpec();
if (spec != null) {
List<Container> containerList = spec.getContainers();
for (Container container : containerList) {
String image = container.getImage();
table.row(id, image, host, labels, status);
id = "";
host = "";
status = "";
labels = "";
}
}
}
}
return table;
}