Java Code Examples for io.fabric8.kubernetes.api.model.Container#getVolumeMounts()

The following examples show how to use io.fabric8.kubernetes.api.model.Container#getVolumeMounts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesDockerRunnerPodResourceTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotHaveSecretsMountIfNoSecret() {
  Pod pod = 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(2));
  assertThat(containers.get(0).getName(), is(MAIN_CONTAINER_NAME));

  Container container = containers.get(0);
  List<VolumeMount> volumeMounts = container.getVolumeMounts();
  assertThat(volumeMounts.size(), is(0));
}
 
Example 2
Source File: KubernetesDockerRunnerPodResourceTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConfigureSecretsMount() {
  WorkflowConfiguration.Secret secret = WorkflowConfiguration.Secret.create("my-secret", "/etc/secrets");
  KubernetesSecretSpec secretSpec = KubernetesSecretSpec.builder()
      .customSecret(secret)
      .build();
  Pod pod = 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(2));
  assertThat(containers.get(0).getName(), is(MAIN_CONTAINER_NAME));

  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));
}
 
Example 3
Source File: KubernetesEnvironmentPodsValidator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void validatePodVolumes(KubernetesEnvironment env) throws ValidationException {
  Set<String> pvcsNames = env.getPersistentVolumeClaims().keySet();
  for (PodData pod : env.getPodsData().values()) {
    Set<String> volumesNames = new HashSet<>();
    for (Volume volume : pod.getSpec().getVolumes()) {
      volumesNames.add(volume.getName());

      PersistentVolumeClaimVolumeSource pvcSource = volume.getPersistentVolumeClaim();
      if (pvcSource != null && !pvcsNames.contains(pvcSource.getClaimName())) {
        throw new ValidationException(
            String.format(
                "Pod '%s' contains volume '%s' with PVC sources that references missing PVC '%s'",
                pod.getMetadata().getName(), volume.getName(), pvcSource.getClaimName()));
      }
    }

    for (Container container : pod.getSpec().getContainers()) {
      for (VolumeMount volumeMount : container.getVolumeMounts()) {
        if (!volumesNames.contains(volumeMount.getName())) {
          throw new ValidationException(
              String.format(
                  "Container '%s' in pod '%s' contains volume mount that references missing volume '%s'",
                  container.getName(), pod.getMetadata().getName(), volumeMount.getName()));
        }
      }
    }
  }
}
 
Example 4
Source File: VcsSslCertificateProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void verifyVolumeMountIsPresent(Container container) {
  List<VolumeMount> volumeMounts = container.getVolumeMounts();
  assertEquals(volumeMounts.size(), 1);
  VolumeMount volumeMount = volumeMounts.get(0);
  assertEquals(volumeMount.getName(), CHE_GIT_SELF_SIGNED_VOLUME);
  assertTrue(volumeMount.getReadOnly());
  assertEquals(volumeMount.getMountPath(), CERT_MOUNT_PATH);
}
 
Example 5
Source File: CertificateProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void verifyVolumeMountIsPresent(Container container) {
  List<VolumeMount> volumeMounts = container.getVolumeMounts();
  assertEquals(volumeMounts.size(), 1);
  VolumeMount volumeMount = volumeMounts.get(0);
  assertEquals(volumeMount.getName(), CHE_SELF_SIGNED_CERT_VOLUME);
  assertTrue(volumeMount.getReadOnly());
  assertEquals(volumeMount.getMountPath(), CERT_MOUNT_PATH);
}
 
Example 6
Source File: PodInfo.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@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());
            }
        }
    }
}