io.fabric8.kubernetes.api.model.Volume Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.Volume. 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: VolumeUtils.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an empty directory volume
 *
 * @param name      Name of the Volume
 * @param sizeLimit Volume size
 * @return The Volume created
 */
public static Volume createEmptyDirVolume(String name, String sizeLimit) {
    String validName = getValidVolumeName(name);

    EmptyDirVolumeSource emptyDirVolumeSource = new EmptyDirVolumeSourceBuilder().build();
    if (sizeLimit != null && !sizeLimit.isEmpty()) {
        emptyDirVolumeSource.setSizeLimit(new Quantity(sizeLimit));
    }

    Volume volume = new VolumeBuilder()
            .withName(validName)
            .withEmptyDir(emptyDirVolumeSource)
            .build();
    log.trace("Created emptyDir Volume named '{}' with sizeLimit '{}'", validName, sizeLimit);
    return volume;
}
 
Example #2
Source File: SecretVolume.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Volume buildVolume(String volumeName) {
    SecretVolumeSource secretVolumeSource = new SecretVolumeSource();
    secretVolumeSource.setSecretName(getSecretName());
    secretVolumeSource.setOptional(getOptional());

    if (StringUtils.isNotBlank(defaultMode)) {
        secretVolumeSource.setDefaultMode(Integer.parseInt(getDefaultMode()));
    }

    return new VolumeBuilder()
            .withName(volumeName)
            .withNewSecretLike(secretVolumeSource)
            .endSecret()
            .build();
}
 
Example #3
Source File: SubPathPrefixesTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldNotPrefixNotPVCSourcesVolumes() {
  // given
  Volume podVolume = pod.getSpec().getVolumes().get(0);
  podVolume.setPersistentVolumeClaim(null);
  podVolume.setConfigMap(new ConfigMapVolumeSourceBuilder().withName("configMap").build());

  // when
  subpathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, WORKSPACE_ID);

  // then
  PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();

  io.fabric8.kubernetes.api.model.Volume podDataVolume = podSpec.getVolumes().get(0);

  Container initContainer = podSpec.getInitContainers().get(0);
  VolumeMount initVolumeMount = initContainer.getVolumeMounts().get(0);
  assertEquals(initVolumeMount.getSubPath(), "/tmp/init/userData");
  assertEquals(initVolumeMount.getName(), podDataVolume.getName());

  Container container = podSpec.getContainers().get(0);
  VolumeMount volumeMount = container.getVolumeMounts().get(0);
  assertEquals(volumeMount.getSubPath(), "/home/user/data");
  assertEquals(volumeMount.getName(), podDataVolume.getName());
}
 
Example #4
Source File: SubPathPrefixesTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldPrefixVolumeMountsSubpathsAndUsePvcNameAsVolumeName() {
  // when
  subpathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, WORKSPACE_ID);

  // then
  PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();

  io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0);
  assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);
  assertEquals(
      podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);

  Container initContainer = podSpec.getInitContainers().get(0);
  VolumeMount initVolumeMount = initContainer.getVolumeMounts().get(0);
  assertEquals(
      initVolumeMount.getSubPath(),
      WORKSPACE_ID + "/" + USER_DATA_PVC_NAME + "/tmp/init/userData");
  assertEquals(initVolumeMount.getName(), userPodVolume.getName());

  Container container = podSpec.getContainers().get(0);
  VolumeMount volumeMount = container.getVolumeMounts().get(0);
  assertEquals(
      volumeMount.getSubPath(), WORKSPACE_ID + "/" + USER_DATA_PVC_NAME + "/home/user/data");
  assertEquals(volumeMount.getName(), userPodVolume.getName());
}
 
Example #5
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 #6
Source File: KubernetesDockerRunnerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnsureAndMountServiceAccountSecret() throws IOException {
  when(serviceAccountSecretManager.ensureServiceAccountKeySecret(
      WORKFLOW_INSTANCE.workflowId().toString(), SERVICE_ACCOUNT)).thenReturn(SERVICE_ACCOUNT_SECRET);

  kdr.start(RUN_STATE, RUN_SPEC_WITH_SA);

  verify(serviceAccountSecretManager).ensureServiceAccountKeySecret(
      WORKFLOW_INSTANCE.workflowId().toString(), SERVICE_ACCOUNT);

  verify(k8sClient).createPod(podCaptor.capture());

  final Pod pod = podCaptor.getValue();

  final Optional<SecretVolumeSource> serviceAccountSecretVolume = pod.getSpec().getVolumes().stream()
      .map(Volume::getSecret)
      .filter(Objects::nonNull)
      .filter(v -> SERVICE_ACCOUNT_SECRET.equals(v.getSecretName()))
      .findAny();

  assertThat(serviceAccountSecretVolume.isPresent(), is(true));
}
 
Example #7
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void doesNotRewritePodConfigMapVolumesWhenNoConfigMap() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  Volume volume =
      new VolumeBuilder().withNewConfigMap().withName(CONFIGMAP_NAME).endConfigMap().build();
  Pod pod = newPod();
  pod.getSpec().setVolumes(ImmutableList.of(volume));
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  Volume newVolume = pod.getSpec().getVolumes().iterator().next();
  assertEquals(newVolume.getConfigMap().getName(), CONFIGMAP_NAME);
}
 
Example #8
Source File: DeploymentPropertiesResolver.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 6 votes vote down vote up
/**
 * Volume deployment properties are specified in YAML format:
 *
 * <code>
 *     spring.cloud.deployer.kubernetes.volumes=[{name: testhostpath, hostPath: { path: '/test/override/hostPath' }},
 *     	{name: 'testpvc', persistentVolumeClaim: { claimName: 'testClaim', readOnly: 'true' }},
 *     	{name: 'testnfs', nfs: { server: '10.0.0.1:111', path: '/test/nfs' }}]
 * </code>
 *
 * Volumes can be specified as deployer properties as well as app deployment properties.
 * Deployment properties override deployer properties.
 *
 * @param kubernetesDeployerProperties the kubernetes deployer properties map
 * @return the configured volumes
 */
List<Volume> getVolumes(Map<String, String> kubernetesDeployerProperties) {
	List<Volume> volumes = new ArrayList<>();

	KubernetesDeployerProperties deployerProperties = bindProperties(kubernetesDeployerProperties,
			this.propertyPrefix + ".volumes", "volumes");

	volumes.addAll(deployerProperties.getVolumes());

	// only add volumes that have not already been added, based on the volume's name
	// i.e. allow provided deployment volumes to override deployer defined volumes
	volumes.addAll(properties.getVolumes().stream()
			.filter(volume -> volumes.stream()
					.noneMatch(existingVolume -> existingVolume.getName().equals(volume.getName())))
			.collect(Collectors.toList()));

	return volumes;
}
 
Example #9
Source File: HadoopConfMountDecoratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testExistingConfigMapPrecedeOverHadoopConfEnv() throws IOException {
	// set existing ConfigMap
	flinkConfig.set(KubernetesConfigOptions.HADOOP_CONF_CONFIG_MAP, EXISTING_HADOOP_CONF_CONFIG_MAP);

	// set HADOOP_CONF_DIR
	setHadoopConfDirEnv();
	generateHadoopConfFileItems();

	assertEquals(0, hadoopConfMountDecorator.buildAccompanyingKubernetesResources().size());

	final FlinkPod resultFlinkPod = hadoopConfMountDecorator.decorateFlinkPod(baseFlinkPod);
	final List<Volume> volumes = resultFlinkPod.getPod().getSpec().getVolumes();
	assertTrue(volumes.stream().anyMatch(volume ->
		volume.getConfigMap().getName().equals(EXISTING_HADOOP_CONF_CONFIG_MAP)));
	assertFalse(volumes.stream().anyMatch(volume ->
		volume.getConfigMap().getName().equals(HadoopConfMountDecorator.getHadoopConfConfigMapName(CLUSTER_ID))));
}
 
Example #10
Source File: KafkaConnectS2IClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoExternalConfigurationVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .build();

    KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource)
            .editSpec()
                .withNewExternalConfiguration()
                    .withVolumes(volume)
                .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));

    List<VolumeMount> volumeMounths = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));
}
 
Example #11
Source File: PodsVolumesTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldChangePVCReference() {
  // given
  podData
      .getSpec()
      .getVolumes()
      .add(
          new VolumeBuilder()
              .withName("userData")
              .withPersistentVolumeClaim(
                  new PersistentVolumeClaimVolumeSourceBuilder()
                      .withClaimName("userData")
                      .build())
              .build());

  // when
  podsVolumes.changePVCReferences(ImmutableList.of(podData), "userData", "newPVCName");

  // then
  assertEquals(podData.getSpec().getVolumes().size(), 1);
  Volume volume = podData.getSpec().getVolumes().get(0);
  assertEquals(volume.getPersistentVolumeClaim().getClaimName(), "newPVCName");
}
 
Example #12
Source File: VolumeUtils.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Kubernetes volume which will map to ConfigMap
 *
 * @param name              Name of the Volume
 * @param configMapName     Name of the ConfigMap
 * @return                  The newly created Volume
 */
public static Volume createConfigMapVolume(String name, String configMapName) {
    String validName = getValidVolumeName(name);

    ConfigMapVolumeSource configMapVolumeSource = new ConfigMapVolumeSourceBuilder()
            .withName(configMapName)
            .build();

    Volume volume = new VolumeBuilder()
            .withName(validName)
            .withConfigMap(configMapVolumeSource)
            .build();

    log.trace("Created configMap Volume named '{}' with source configMap '{}'", validName, configMapName);

    return volume;
}
 
Example #13
Source File: KafkaConnectClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoExternalConfigurationVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .build();

    KafkaConnect resource = new KafkaConnectBuilder(this.resource)
            .editSpec()
            .withNewExternalConfiguration()
            .withVolumes(volume)
            .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kc.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));

    List<VolumeMount> volumeMounths = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));
}
 
Example #14
Source File: KafkaConnectCluster.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
protected List<Volume> getVolumes(boolean isOpenShift) {
    List<Volume> volumeList = new ArrayList<>(1);
    volumeList.add(VolumeUtils.createConfigMapVolume(logAndMetricsConfigVolumeName, ancillaryConfigMapName));

    if (tls != null) {
        List<CertSecretSource> trustedCertificates = tls.getTrustedCertificates();

        if (trustedCertificates != null && trustedCertificates.size() > 0) {
            for (CertSecretSource certSecretSource : trustedCertificates) {
                // skipping if a volume with same Secret name was already added
                if (!volumeList.stream().anyMatch(v -> v.getName().equals(certSecretSource.getSecretName()))) {
                    volumeList.add(VolumeUtils.createSecretVolume(certSecretSource.getSecretName(), certSecretSource.getSecretName(), isOpenShift));
                }
            }
        }
    }

    AuthenticationUtils.configureClientAuthenticationVolumes(authentication, volumeList, "oauth-certs", isOpenShift);

    volumeList.addAll(getExternalConfigurationVolumes(isOpenShift));

    return volumeList;
}
 
Example #15
Source File: KafkaMirrorMaker2ClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoExternalConfigurationVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .build();

    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource)
            .editSpec()
            .withNewExternalConfiguration()
            .withVolumes(volume)
            .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));

    List<VolumeMount> volumeMounths = getContainer(dep).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));
}
 
Example #16
Source File: KafkaBridgeCluster.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
protected List<Volume> getVolumes(boolean isOpenShift) {
    List<Volume> volumeList = new ArrayList<>(1);
    volumeList.add(VolumeUtils.createConfigMapVolume(logAndMetricsConfigVolumeName, ancillaryConfigMapName));

    if (tls != null) {
        List<CertSecretSource> trustedCertificates = tls.getTrustedCertificates();

        if (trustedCertificates != null && trustedCertificates.size() > 0) {
            for (CertSecretSource certSecretSource : trustedCertificates) {
                // skipping if a volume with same Secret name was already added
                if (!volumeList.stream().anyMatch(v -> v.getName().equals(certSecretSource.getSecretName()))) {
                    volumeList.add(VolumeUtils.createSecretVolume(certSecretSource.getSecretName(), certSecretSource.getSecretName(), isOpenShift));
                }
            }
        }
    }

    AuthenticationUtils.configureClientAuthenticationVolumes(authentication, volumeList, "oauth-certs", isOpenShift);

    return volumeList;
}
 
Example #17
Source File: FlinkConfMountDecoratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecoratedFlinkPodWithoutLog4jAndLogback() {
	final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);

	final List<KeyToPath> expectedKeyToPaths = Collections.singletonList(
		new KeyToPathBuilder()
			.withKey(FLINK_CONF_FILENAME)
			.withPath(FLINK_CONF_FILENAME)
			.build());
	final List<Volume> expectedVolumes = Collections.singletonList(
		new VolumeBuilder()
			.withName(Constants.FLINK_CONF_VOLUME)
			.withNewConfigMap()
				.withName(getFlinkConfConfigMapName(CLUSTER_ID))
				.withItems(expectedKeyToPaths)
				.endConfigMap()
			.build());
	assertEquals(expectedVolumes, resultFlinkPod.getPod().getSpec().getVolumes());

	final List<VolumeMount> expectedVolumeMounts = Collections.singletonList(
		new VolumeMountBuilder()
			.withName(Constants.FLINK_CONF_VOLUME)
			.withMountPath(FLINK_CONF_DIR_IN_POD)
		.build());
	assertEquals(expectedVolumeMounts, resultFlinkPod.getMainContainer().getVolumeMounts());
}
 
Example #18
Source File: KafkaConnectClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalConfigurationSecretVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .withSecret(new SecretVolumeSourceBuilder().withSecretName("my-secret").build())
            .build();

    KafkaConnect resource = new KafkaConnectBuilder(this.resource)
            .editSpec()
                .withNewExternalConfiguration()
                    .withVolumes(volume)
                .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kc.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selected.get(0).getName(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selected.get(0).getSecret(), is(volume.getSecret()));

    List<VolumeMount> volumeMounths = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selectedVolumeMounths.get(0).getName(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selectedVolumeMounths.get(0).getMountPath(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_MOUNT_BASE_PATH + "my-volume"));
}
 
Example #19
Source File: ConfigMapVolume.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Volume buildVolume(String volumeName) {
    return new VolumeBuilder()
            .withName(volumeName)
            .withNewConfigMap()
                .withName(getConfigMapName())
                .withOptional(getOptional())
            .and()
            .build();
}
 
Example #20
Source File: KafkaConnectClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalConfigurationConfigVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .withConfigMap(new ConfigMapVolumeSourceBuilder().withName("my-map").build())
            .build();

    KafkaConnect resource = new KafkaConnectBuilder(this.resource)
            .editSpec()
            .withNewExternalConfiguration()
                .withVolumes(volume)
            .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kc.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selected.get(0).getName(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selected.get(0).getConfigMap(), is(volume.getConfigMap()));

    List<VolumeMount> volumeMounths = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selectedVolumeMounths.get(0).getName(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selectedVolumeMounths.get(0).getMountPath(), is(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_MOUNT_BASE_PATH + "my-volume"));
}
 
Example #21
Source File: KafkaAssemblyOperatorMockTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
private void assertVolumes(VertxTestContext context, String statefulSetName, List<Volume> originalVolumes) {
    context.verify(() -> {
        StatefulSet statefulSet = client.apps().statefulSets().inNamespace(NAMESPACE).withName(statefulSetName).get();
        assertThat(statefulSet, is(notNullValue()));
        List<Volume> volumes = statefulSet.getSpec().getTemplate().getSpec().getVolumes();
        assertThat(originalVolumes.size(), is(volumes.size()));
        assertThat(originalVolumes, is(volumes));
    });
}
 
Example #22
Source File: PodTemplateHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private List<Volume> getVolumes(ResourceConfig config) {
    List<VolumeConfig> volumeConfigs = config.getVolumes();

    List<Volume> ret = new ArrayList<>();
    if (volumeConfigs != null) {
        for (VolumeConfig volumeConfig : volumeConfigs) {
            VolumeType type = VolumeType.typeFor(volumeConfig.getType());
            if (type != null) {
                ret.add(type.fromConfig(volumeConfig));
            }
        }
    }
    return ret;
}
 
Example #23
Source File: SubPathPrefixesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldPrefixVolumeMountsSubpathsAndUseVolumeNameStoredInLabels() {
  // given
  String volumeName = "userDataVolume";
  pvc.getMetadata().getLabels().put(CHE_VOLUME_NAME_LABEL, volumeName);

  // when
  subpathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, WORKSPACE_ID);

  // then
  PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();

  io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0);
  assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);
  assertEquals(
      podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);

  Container initContainer = podSpec.getInitContainers().get(0);
  VolumeMount initVolumeMount = initContainer.getVolumeMounts().get(0);
  assertEquals(
      initVolumeMount.getSubPath(), WORKSPACE_ID + "/" + volumeName + "/tmp/init/userData");
  assertEquals(initVolumeMount.getName(), userPodVolume.getName());

  Container container = podSpec.getContainers().get(0);
  VolumeMount volumeMount = container.getVolumeMounts().get(0);
  assertEquals(volumeMount.getSubPath(), WORKSPACE_ID + "/" + volumeName + "/home/user/data");
  assertEquals(volumeMount.getName(), userPodVolume.getName());
}
 
Example #24
Source File: FlinkConfMountDecorator.java    From flink with Apache License 2.0 5 votes vote down vote up
private Pod decoratePod(Pod pod) {
	final List<KeyToPath> keyToPaths = getLocalLogConfFiles().stream()
		.map(file -> new KeyToPathBuilder()
			.withKey(file.getName())
			.withPath(file.getName())
			.build())
		.collect(Collectors.toList());
	keyToPaths.add(new KeyToPathBuilder()
		.withKey(FLINK_CONF_FILENAME)
		.withPath(FLINK_CONF_FILENAME)
		.build());

	final Volume flinkConfVolume = new VolumeBuilder()
		.withName(FLINK_CONF_VOLUME)
		.withNewConfigMap()
			.withName(getFlinkConfConfigMapName(kubernetesComponentConf.getClusterId()))
			.withItems(keyToPaths)
			.endConfigMap()
		.build();

	return new PodBuilder(pod)
		.editSpec()
			.addNewVolumeLike(flinkConfVolume)
			.endVolume()
			.endSpec()
		.build();
}
 
Example #25
Source File: KafkaMirrorMaker2ClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalConfigurationInvalidVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .withConfigMap(new ConfigMapVolumeSourceBuilder().withName("my-map").build())
            .withSecret(new SecretVolumeSourceBuilder().withSecretName("my-secret").build())
            .build();

    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource)
            .editSpec()
                .withNewExternalConfiguration()
                    .withVolumes(volume)
                .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));

    List<VolumeMount> volumeMounths = getContainer(dep).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));
}
 
Example #26
Source File: KafkaMirrorMaker2ClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalConfigurationSecretVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .withSecret(new SecretVolumeSourceBuilder().withSecretName("my-secret").build())
            .build();

    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource)
            .editSpec()
                .withNewExternalConfiguration()
                    .withVolumes(volume)
                .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selected.get(0).getName(), is(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selected.get(0).getSecret(), is(volume.getSecret()));

    List<VolumeMount> volumeMounths = getContainer(dep).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(1));
    assertThat(selectedVolumeMounths.get(0).getName(), is(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume"));
    assertThat(selectedVolumeMounths.get(0).getMountPath(), is(KafkaMirrorMaker2Cluster.EXTERNAL_CONFIGURATION_VOLUME_MOUNT_BASE_PATH + "my-volume"));
}
 
Example #27
Source File: BrokerEnvironmentFactory.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Volume newConfigMapVolume(String configMapName, String configMapVolume) {
  return new VolumeBuilder()
      .withName(configMapVolume)
      .withNewConfigMap()
      .withName(configMapName)
      .endConfigMap()
      .build();
}
 
Example #28
Source File: VcsSslCertificateProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void verifyVolumeIsPresent(Pod pod) {
  List<Volume> podVolumes = pod.getSpec().getVolumes();
  assertEquals(podVolumes.size(), 1);
  Volume certVolume = podVolumes.get(0);
  assertEquals(certVolume.getName(), CHE_GIT_SELF_SIGNED_VOLUME);
  ConfigMapVolumeSource volumeConfigMap = certVolume.getConfigMap();
  assertNotNull(volumeConfigMap);
  assertEquals(volumeConfigMap.getName(), EXPECTED_CERT_NAME);
}
 
Example #29
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 #30
Source File: KafkaConnectS2IClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalConfigurationInvalidVolumes() {
    ExternalConfigurationVolumeSource volume = new ExternalConfigurationVolumeSourceBuilder()
            .withName("my-volume")
            .withConfigMap(new ConfigMapVolumeSourceBuilder().withName("my-map").build())
            .withSecret(new SecretVolumeSourceBuilder().withSecretName("my-secret").build())
            .build();

    KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource)
            .editSpec()
                .withNewExternalConfiguration()
                    .withVolumes(volume)
                .endExternalConfiguration()
            .endSpec()
            .build();
    KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS);

    // Check Deployment
    DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null);
    List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes();
    List<Volume> selected = volumes.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));

    List<VolumeMount> volumeMounths = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts();
    List<VolumeMount> selectedVolumeMounths = volumeMounths.stream().filter(vol -> vol.getName().equals(KafkaConnectCluster.EXTERNAL_CONFIGURATION_VOLUME_NAME_PREFIX + "my-volume")).collect(Collectors.toList());
    assertThat(selected.size(), is(0));
}