本文整理汇总了Java中io.fabric8.kubernetes.api.model.VolumeMount类的典型用法代码示例。如果您正苦于以下问题:Java VolumeMount类的具体用法?Java VolumeMount怎么用?Java VolumeMount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VolumeMount类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了VolumeMount类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldNotHaveSecretsMountIfNoSecret
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
@Test
public void shouldNotHaveSecretsMountIfNoSecret() throws Exception {
Pod pod = KubernetesDockerRunner.createPod(
WORKFLOW_INSTANCE,
DockerRunner.RunSpec.simple("eid", "busybox"), EMPTY_SECRET_SPEC);
List<Volume> volumes = pod.getSpec().getVolumes();
List<Container> containers = pod.getSpec().getContainers();
assertThat(volumes.size(), is(0));
assertThat(containers.size(), is(1));
Container container = containers.get(0);
List<VolumeMount> volumeMounts = container.getVolumeMounts();
assertThat(volumeMounts.size(), is(0));
}
开发者ID:spotify,项目名称:styx,代码行数:16,代码来源:KubernetesDockerRunnerPodResourceTest.java
示例2: shouldConfigureSecretsMount
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
@Test
public void shouldConfigureSecretsMount() throws Exception {
WorkflowConfiguration.Secret secret = WorkflowConfiguration.Secret.create("my-secret", "/etc/secrets");
KubernetesSecretSpec secretSpec = KubernetesSecretSpec.builder()
.customSecret(secret)
.build();
Pod pod = KubernetesDockerRunner.createPod(
WORKFLOW_INSTANCE,
DockerRunner.RunSpec.builder()
.executionId("eid")
.imageName("busybox")
.secret(secret)
.build(),
secretSpec);
List<Volume> volumes = pod.getSpec().getVolumes();
List<Container> containers = pod.getSpec().getContainers();
assertThat(volumes.size(), is(1));
assertThat(containers.size(), is(1));
Volume volume = volumes.get(0);
assertThat(volume.getName(), is("my-secret"));
assertThat(volume.getSecret().getSecretName(), is("my-secret"));
Container container = containers.get(0);
List<VolumeMount> volumeMounts = container.getVolumeMounts();
assertThat(volumeMounts.size(), is(1));
VolumeMount volumeMount = volumeMounts.get(0);
assertThat(volumeMount.getName(), is("my-secret"));
assertThat(volumeMount.getMountPath(), is("/etc/secrets"));
assertThat(volumeMount.getReadOnly(), is(true));
}
开发者ID:spotify,项目名称:styx,代码行数:34,代码来源:KubernetesDockerRunnerPodResourceTest.java
示例3: getVolumeMounts
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
/**
* Volume mount deployment properties are specified in YAML format:
* <p>
* <code>
* spring.cloud.deployer.kubernetes.volumeMounts=[{name: 'testhostpath', mountPath: '/test/hostPath'},
* {name: 'testpvc', mountPath: '/test/pvc'}, {name: 'testnfs', mountPath: '/test/nfs'}]
* </code>
* <p>
* Volume mounts can be specified as deployer properties as well as app deployment properties.
* Deployment properties override deployer properties.
*
* @param request
* @return the configured volume mounts
*/
protected List<VolumeMount> getVolumeMounts(AppDeploymentRequest request) {
List<VolumeMount> volumeMounts = new ArrayList<>();
String volumeMountDeploymentProperty = request.getDeploymentProperties()
.getOrDefault("spring.cloud.deployer.kubernetes.volumeMounts", "");
if (!StringUtils.isEmpty(volumeMountDeploymentProperty)) {
YamlConfigurationFactory<KubernetesDeployerProperties> volumeMountYamlConfigurationFactory = new YamlConfigurationFactory<>(
KubernetesDeployerProperties.class);
volumeMountYamlConfigurationFactory.setYaml("{ volumeMounts: " + volumeMountDeploymentProperty + " }");
try {
volumeMountYamlConfigurationFactory.afterPropertiesSet();
volumeMounts.addAll(volumeMountYamlConfigurationFactory.getObject().getVolumeMounts());
}
catch (Exception e) {
throw new IllegalArgumentException(
String.format("Invalid volume mount '%s'", volumeMountDeploymentProperty), e);
}
}
// only add volume mounts that have not already been added, based on the volume mount's name
// i.e. allow provided deployment volume mounts to override deployer defined volume mounts
volumeMounts.addAll(properties.getVolumeMounts().stream().filter(volumeMount -> volumeMounts.stream()
.noneMatch(existingVolumeMount -> existingVolumeMount.getName().equals(volumeMount.getName())))
.collect(Collectors.toList()));
return volumeMounts;
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:41,代码来源:DefaultContainerFactory.java
示例4: newVolumeMount
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
/** Returns new instance of {@link VolumeMount} with specified name, mountPath and subPath. */
public static VolumeMount newVolumeMount(String name, String mountPath, String subPath) {
return new VolumeMountBuilder()
.withMountPath(mountPath)
.withName(name)
.withSubPath(subPath)
.build();
}
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:OpenShiftObjectUtil.java
示例5: volumeMountExists
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
public static boolean volumeMountExists(String path, Iterable<VolumeMount> existingMounts) {
for (VolumeMount mount : existingMounts) {
if (mount.getMountPath().equals(path)) {
return true;
}
}
return false;
}
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:9,代码来源:PodVolume.java
示例6: createContainer
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
protected Container createContainer(final String imageName,
final ImagePullPolicy imagePullPolicy,
final String namespace,
final boolean tls,
final boolean verifyTls) {
final Container container = new Container();
container.setName(DEFAULT_NAME);
container.setImage(normalizeImageName(imageName));
container.setImagePullPolicy(normalizeImagePullPolicy(imagePullPolicy));
final ContainerPort containerPort = new ContainerPort();
containerPort.setContainerPort(Integer.valueOf(44134));
containerPort.setName(DEFAULT_NAME);
container.setPorts(Arrays.asList(containerPort));
final List<EnvVar> env = new ArrayList<>();
final EnvVar tillerNamespace = new EnvVar();
tillerNamespace.setName("TILLER_NAMESPACE");
tillerNamespace.setValue(normalizeNamespace(namespace));
env.add(tillerNamespace);
if (tls) {
final EnvVar tlsVerify = new EnvVar();
tlsVerify.setName("TILLER_TLS_VERIFY");
tlsVerify.setValue(verifyTls ? "1" : "");
env.add(tlsVerify);
final EnvVar tlsEnable = new EnvVar();
tlsEnable.setName("TILLER_TLS_ENABLE");
tlsEnable.setValue("1");
env.add(tlsEnable);
final EnvVar tlsCerts = new EnvVar();
tlsCerts.setName("TILLER_TLS_CERTS");
tlsCerts.setValue(TILLER_TLS_CERTS_PATH);
env.add(tlsCerts);
}
container.setEnv(env);
final IntOrString port44135 = new IntOrString(Integer.valueOf(44135));
final HTTPGetAction livenessHttpGetAction = new HTTPGetAction();
livenessHttpGetAction.setPath("/liveness");
livenessHttpGetAction.setPort(port44135);
final Probe livenessProbe = new Probe();
livenessProbe.setHttpGet(livenessHttpGetAction);
livenessProbe.setInitialDelaySeconds(ONE);
livenessProbe.setTimeoutSeconds(ONE);
container.setLivenessProbe(livenessProbe);
final HTTPGetAction readinessHttpGetAction = new HTTPGetAction();
readinessHttpGetAction.setPath("/readiness");
readinessHttpGetAction.setPort(port44135);
final Probe readinessProbe = new Probe();
readinessProbe.setHttpGet(readinessHttpGetAction);
readinessProbe.setInitialDelaySeconds(ONE);
readinessProbe.setTimeoutSeconds(ONE);
container.setReadinessProbe(readinessProbe);
if (tls) {
final VolumeMount volumeMount = new VolumeMount();
volumeMount.setName(DEFAULT_NAME + "-certs");
volumeMount.setReadOnly(true);
volumeMount.setMountPath(TILLER_TLS_CERTS_PATH);
container.setVolumeMounts(Arrays.asList(volumeMount));
}
return container;
}
开发者ID:microbean,项目名称:microbean-helm,代码行数:73,代码来源:TillerInstaller.java
示例7: executePod
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
@Override
protected void executePod(Pod podInfo, String podId) {
System.out.println("Created: " + podInfo.getMetadata().getCreationTimestamp());
System.out.println("Labels: ");
Map<String, String> labels = podInfo.getMetadata().getLabels();
for (Map.Entry<String, String> entry : labels.entrySet()) {
System.out.println(indent + entry.getKey() + " = " + entry.getValue());
}
PodStatus currentState = podInfo.getStatus();
if (currentState != null) {
printValue("Host", currentState.getHostIP());
printValue("IP", currentState.getPodIP());
printValue("Status", getStatusText(currentState));
}
PodSpec spec = podInfo.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (notEmpty(containers)) {
System.out.println("Containers:");
indentCount++;
for (Container container : containers) {
printValue("Name", container.getName());
printValue("Image", container.getImage());
printValue("Working Dir", container.getWorkingDir());
printValue("Command", container.getCommand());
List<ContainerPort> ports = container.getPorts();
if (notEmpty(ports)) {
println("Ports:");
indentCount++;
for (ContainerPort port : ports) {
printValue("Name", port.getName());
printValue("Protocol", port.getProtocol());
printValue("Host Port", port.getHostPort());
printValue("Container Port", port.getContainerPort());
}
indentCount--;
}
List<EnvVar> envList = container.getEnv();
if (notEmpty(envList)) {
println("Environment:");
indentCount++;
for (EnvVar env : envList) {
printValue(env.getName(), env.getValue());
}
indentCount--;
}
List<VolumeMount> volumeMounts = container.getVolumeMounts();
if (notEmpty(volumeMounts)) {
println("Volume Mounts:");
indentCount++;
for (VolumeMount volumeMount : volumeMounts) {
printValue("Name", volumeMount.getName());
printValue("Mount Path", volumeMount.getMountPath());
printValue("Read Only", volumeMount.getReadOnly());
}
indentCount--;
}
}
}
List<Volume> volumes = spec.getVolumes();
if (volumes != null) {
System.out.println("Volumes: ");
for (Volume volume : volumes) {
System.out.println(indent + volume.getName());
}
}
}
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:72,代码来源:PodInfo.java
示例8: createPod
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的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
示例9: getVolumeMounts
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
public List<VolumeMount> getVolumeMounts() {
return volumeMounts;
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:4,代码来源:KubernetesDeployerProperties.java
示例10: setVolumeMounts
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
public void setVolumeMounts(List<VolumeMount> volumeMounts) {
this.volumeMounts = volumeMounts;
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:4,代码来源:KubernetesDeployerProperties.java
示例11: createWithVolumeMounts
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
@Test
public void createWithVolumeMounts() {
// test volume mounts defined as deployer properties
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.volumeMounts",
"["
+ "{name: 'testhostpath', mountPath: '/test/hostPath'}, "
+ "{name: 'testpvc', mountPath: '/test/pvc', readOnly: 'true'}, "
+ "{name: 'testnfs', mountPath: '/test/nfs'}"
+ "]");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, resource, props);
Container container = defaultContainerFactory.create("app-test", appDeploymentRequest, null, null, false);
assertThat(container.getVolumeMounts()).containsOnly(
new VolumeMount("/test/hostPath", "testhostpath", null, null),
new VolumeMount("/test/pvc", "testpvc", true, null),
new VolumeMount("/test/nfs", "testnfs", null, null));
// test volume mounts defined as app deployment property, overriding the deployer property
kubernetesDeployerProperties = new KubernetesDeployerProperties();
kubernetesDeployerProperties
.setVolumeMounts(Stream.of(
new VolumeMount("/test/hostPath", "testhostpath", false, null),
new VolumeMount("/test/pvc", "testpvc", true, null),
new VolumeMount("/test/nfs", "testnfs", false, null))
.collect(Collectors.toList()));
defaultContainerFactory = new DefaultContainerFactory(kubernetesDeployerProperties);
props.clear();
props.put("spring.cloud.deployer.kubernetes.volumeMounts",
"["
+ "{name: 'testpvc', mountPath: '/test/pvc/overridden'}, "
+ "{name: 'testnfs', mountPath: '/test/nfs/overridden', readOnly: 'true'}"
+ "]");
container = defaultContainerFactory.create("app-test", appDeploymentRequest, null, null, false);
assertThat(container.getVolumeMounts()).containsOnly(
new VolumeMount("/test/hostPath", "testhostpath", false, null),
new VolumeMount("/test/pvc/overridden", "testpvc", null, null),
new VolumeMount("/test/nfs/overridden", "testnfs", true, null));
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:48,代码来源:DefaultContainerFactoryTests.java
示例12: testDeploymentWithMountedHostPathVolume
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
@Test
public void testDeploymentWithMountedHostPathVolume() throws IOException {
log.info("Testing {}...", "DeploymentWithMountedVolume");
String hostPath = "/tmp/" + randomName() + '/';
String containerPath = "/tmp/";
String subPath = randomName();
String mountName = "mount";
KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties();
deployProperties.setCreateDeployment(originalProperties.isCreateDeployment());
deployProperties.setVolumes(Collections.singletonList(new VolumeBuilder()
.withHostPath(new HostPathVolumeSource(hostPath))
.withName(mountName)
.build()));
deployProperties.setVolumeMounts(Collections.singletonList(new VolumeMount(hostPath, mountName, false, null)));
ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties);
KubernetesAppDeployer lbAppDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient, containerFactory);
AppDefinition definition = new AppDefinition(randomName(), Collections.singletonMap("logging.file", containerPath + subPath));
Resource resource = testApplication();
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);
log.info("Deploying {}...", request.getDefinition().getName());
String deploymentId = lbAppDeployer.deploy(request);
Timeout timeout = deploymentTimeout();
assertThat(deploymentId, eventually(hasStatusThat(
Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));
Map<String, String> selector = Collections.singletonMap(SPRING_APP_KEY, deploymentId);
PodSpec spec = kubernetesClient.pods().withLabels(selector).list().getItems().get(0).getSpec();
assertThat(spec.getVolumes(), is(notNullValue()));
Volume volume = spec.getVolumes().stream()
.filter(v -> mountName.equals(v.getName()))
.findAny()
.orElseThrow(() -> new AssertionError("Volume not mounted"));
assertThat(volume.getHostPath(), is(notNullValue()));
assertThat(hostPath, is(volume.getHostPath().getPath()));
log.info("Undeploying {}...", deploymentId);
timeout = undeploymentTimeout();
lbAppDeployer.undeploy(deploymentId);
assertThat(deploymentId, eventually(hasStatusThat(
Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));
}
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-kubernetes,代码行数:44,代码来源:KubernetesAppDeployerIntegrationTests.java
示例13: volumeMountExists
import io.fabric8.kubernetes.api.model.VolumeMount; //导入依赖的package包/类
/**
* @deprecated Use {@link PodVolume#volumeMountExists(String, List)} instead
*/
public static boolean volumeMountExists(String path, List<VolumeMount> existingMounts) {
return PodVolume.volumeMountExists(path, existingMounts);
}
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:7,代码来源:PodVolumes.java
注:本文中的io.fabric8.kubernetes.api.model.VolumeMount类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论