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

The following examples show how to use io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder. 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 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 #2
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 #3
Source File: GitConfigProvisioner.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private void mountConfigFile(PodSpec podSpec, String gitConfigMapName, boolean addVolume) {
  if (addVolume) {
    podSpec
        .getVolumes()
        .add(
            new VolumeBuilder()
                .withName(CONFIG_MAP_VOLUME_NAME)
                .withConfigMap(
                    new ConfigMapVolumeSourceBuilder().withName(gitConfigMapName).build())
                .build());
  }

  List<Container> containers = podSpec.getContainers();
  containers.forEach(
      container -> {
        VolumeMount volumeMount =
            new VolumeMountBuilder()
                .withName(CONFIG_MAP_VOLUME_NAME)
                .withMountPath(GIT_CONFIG_PATH)
                .withSubPath(GIT_CONFIG)
                .withReadOnly(false)
                .withNewReadOnly(false)
                .build();
        container.getVolumeMounts().add(volumeMount);
      });
}
 
Example #4
Source File: KafkaMirrorMaker2ClusterTest.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();

    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).getConfigMap(), is(volume.getConfigMap()));

    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 #5
Source File: SshKeysProvisioner.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void mountConfigFile(PodSpec podSpec, String sshConfigMapName, boolean addVolume) {
  String configMapVolumeName = "ssshkeyconfigvolume";
  if (addVolume) {
    podSpec
        .getVolumes()
        .add(
            new VolumeBuilder()
                .withName(configMapVolumeName)
                .withConfigMap(
                    new ConfigMapVolumeSourceBuilder().withName(sshConfigMapName).build())
                .build());
  }

  List<Container> containers = podSpec.getContainers();
  containers.forEach(
      container -> {
        VolumeMount volumeMount =
            new VolumeMountBuilder()
                .withName(configMapVolumeName)
                .withMountPath(SSH_CONFIG_PATH)
                .withSubPath(SSH_CONFIG)
                .withReadOnly(true)
                .withNewReadOnly(true)
                .build();
        container.getVolumeMounts().add(volumeMount);
      });
}
 
Example #6
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));
}
 
Example #7
Source File: KafkaConnectS2IClusterTest.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();

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

    // Check DeploymentConfig
    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(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 #8
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 #9
Source File: KafkaConnectClusterTest.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();

    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 #10
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 #11
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpecVolumesIgnored() {
    StatefulSet ss1 = new StatefulSetBuilder()
        .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
        .endMetadata()
        .withNewSpec().
            withNewTemplate()
                .withNewSpec()
                    .addToVolumes(0, new VolumeBuilder()
                                .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build())
                            .build())
                .endSpec()
            .endTemplate()
        .endSpec()
        .build();
    StatefulSet ss2 = new StatefulSetBuilder()
        .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
        .endMetadata()
        .withNewSpec()
            .withNewTemplate()
                .withNewSpec()
                    .addToVolumes(0, new VolumeBuilder()
                            .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build())
                            .build())
                .endSpec()
            .endTemplate()
        .endSpec()
        .build();
    assertThat(new StatefulSetDiff(ss1, ss2).changesSpecTemplate(), is(false));
}
 
Example #12
Source File: RabbitMQPods.java    From rabbitmq-operator with Apache License 2.0 4 votes vote down vote up
public PodSpec buildPodSpec(
        final String rabbitName,
        final String initContainerImage,
        final Container container
) {
    return new PodSpecBuilder()
            .withServiceAccountName("rabbitmq-user")
            .addNewInitContainer()
            .withName("copy-rabbitmq-config")
            .withImage(initContainerImage)
            .withCommand(new String[]{"sh", "-c", "cp /configmap/* /etc/rabbitmq"})
            .addNewVolumeMount().withName("config").withMountPath("/etc/rabbitmq").endVolumeMount()
            .addNewVolumeMount().withName("configmap").withMountPath("/configmap").endVolumeMount()
            .endInitContainer()
            .withContainers(container)
            .addNewVolume().withName("config").withEmptyDir(new EmptyDirVolumeSource()).endVolume()
            .addNewVolume().withName("configmap").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-config")
                            .addNewItem("rabbitmq.conf", 0644, "rabbitmq.conf")
                            .addNewItem("enabled_plugins", 0644, "enabled_plugins")
                            .build()
            ).endVolume()
            .addNewVolume().withName("probes").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-probes")
                            .addNewItem("readiness.sh", 0755, "readiness.sh")
                            .build()
            ).endVolume()
            .addNewVolume().withName("startup-scripts").withConfigMap(
                    new ConfigMapVolumeSourceBuilder()
                            .withName("rabbitmq-startup-scripts")
                            .addNewItem("users.sh", 0755, "users.sh")
                            .build()
            ).endVolume()
            .withNewAffinity().withNewPodAntiAffinity().withPreferredDuringSchedulingIgnoredDuringExecution(
                    new WeightedPodAffinityTermBuilder()
                            .withNewWeight(1)
                            .withNewPodAffinityTerm()
                                    .withNewLabelSelector()
                                            .addToMatchLabels(Labels.Kubernetes.INSTANCE, rabbitName)
                                    .endLabelSelector()
                                    .withTopologyKey("kubernetes.io/hostname")
                            .endPodAffinityTerm()
                            .build()
            ).endPodAntiAffinity().endAffinity()
            .build();
}
 
Example #13
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
public void testNewPvcNotIgnored() {
    StatefulSet ss1 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
                .withNewTemplate()
                    .withNewSpec()
                        .addToVolumes(0, new VolumeBuilder()
                                .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build())
                                .build())
                    .endSpec()
                .endTemplate()
                .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                        .withNewSpec()
                        .withNewResources()
                        .withRequests(singletonMap("storage", new Quantity("100Gi")))
                        .endResources()
                        .endSpec()
                        .build())
            .endSpec()
            .build();
    StatefulSet ss2 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
                .withNewTemplate()
                    .withNewSpec()
                        .addToVolumes(0, new VolumeBuilder()
                                .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build())
                                .build())
                    .endSpec()
                .endTemplate()
                .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                        .withNewSpec()
                        .withNewResources()
                        .withRequests(singletonMap("storage", new Quantity("100Gi")))
                        .endResources()
                        .endSpec()
                        .build(),
                        new PersistentVolumeClaimBuilder()
                                .withNewSpec()
                                .withNewResources()
                                .withRequests(singletonMap("storage", new Quantity("110Gi")))
                                .endResources()
                                .endSpec()
                                .build())
            .endSpec()
            .build();
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeClaimTemplates(), is(true));
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeSize(), is(false));
}
 
Example #14
Source File: VcsSslCertificateProvisioner.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private Volume buildCertVolume(String configMapName) {
  return new VolumeBuilder()
      .withName(CHE_GIT_SELF_SIGNED_VOLUME)
      .withConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName).build())
      .build();
}
 
Example #15
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
public void testPvcSizeUnitChangeIgnored() {
    StatefulSet ss1 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
            .withNewTemplate()
            .withNewSpec()
            .addToVolumes(0, new VolumeBuilder()
                    .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build())
                    .build())
            .endSpec()
            .endTemplate()
            .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                    .withNewSpec()
                    .withNewResources()
                    .withRequests(singletonMap("storage", new Quantity("3072Gi")))
                    .endResources()
                    .endSpec()
                    .build())
            .endSpec()
            .build();
    StatefulSet ss2 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
            .withNewTemplate()
            .withNewSpec()
            .addToVolumes(0, new VolumeBuilder()
                    .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build())
                    .build())
            .endSpec()
            .endTemplate()
            .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                    .withNewSpec()
                    .withNewResources()
                    .withRequests(singletonMap("storage", new Quantity("3Ti")))
                    .endResources()
                    .endSpec()
                    .build())
            .endSpec()
            .build();
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeClaimTemplates(), is(false));
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeSize(), is(false));
}
 
Example #16
Source File: StatefulSetDiffTest.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
public void testPvcSizeChangeIgnored() {
    StatefulSet ss1 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
                .withNewTemplate()
                    .withNewSpec()
                        .addToVolumes(0, new VolumeBuilder()
                                .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build())
                                .build())
                    .endSpec()
                .endTemplate()
                .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                        .withNewSpec()
                            .withNewResources()
                                .withRequests(singletonMap("storage", new Quantity("100Gi")))
                            .endResources()
                        .endSpec()
                        .build())
            .endSpec()
            .build();
    StatefulSet ss2 = new StatefulSetBuilder()
            .withNewMetadata()
            .withNamespace("test")
            .withName("foo")
            .endMetadata()
            .withNewSpec()
                .withNewTemplate()
                    .withNewSpec()
                        .addToVolumes(0, new VolumeBuilder()
                                .withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build())
                                .build())
                    .endSpec()
                .endTemplate()
                .withVolumeClaimTemplates(new PersistentVolumeClaimBuilder()
                        .withNewSpec()
                        .withNewResources()
                        .withRequests(singletonMap("storage", new Quantity("110Gi")))
                        .endResources()
                        .endSpec()
                        .build())
            .endSpec()
            .build();
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeClaimTemplates(), is(false));
    assertThat(new StatefulSetDiff(ss1, ss2).changesVolumeSize(), is(true));
}
 
Example #17
Source File: PodsVolumesTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void shouldNotReplaceNonPVCVolumes() {
  // given
  podData
      .getSpec()
      .getInitContainers()
      .add(
          new ContainerBuilder()
              .withName("userInitContainer")
              .withVolumeMounts(new VolumeMountBuilder().withName("configMap").build())
              .build());

  podData
      .getSpec()
      .getContainers()
      .get(0)
      .getVolumeMounts()
      .add(new VolumeMountBuilder().withName("secret").withSubPath("/home/user/data").build());

  podData
      .getSpec()
      .getVolumes()
      .add(
          new VolumeBuilder()
              .withName("configMap")
              .withConfigMap(new ConfigMapVolumeSourceBuilder().withName("configMap").build())
              .build());
  podData
      .getSpec()
      .getVolumes()
      .add(
          new VolumeBuilder()
              .withName("secret")
              .withSecret(new SecretVolumeSourceBuilder().withSecretName("secret").build())
              .build());

  // when
  podsVolumes.replacePVCVolumesWithCommon(ImmutableMap.of("pod", podData), "commonPVC");

  // then
  assertEquals(podData.getSpec().getVolumes().size(), 2);
  assertNotNull(podData.getSpec().getVolumes().get(0).getConfigMap());
  assertNull(podData.getSpec().getVolumes().get(0).getPersistentVolumeClaim());

  assertNotNull(podData.getSpec().getVolumes().get(1).getSecret());
  assertNull(podData.getSpec().getVolumes().get(1).getPersistentVolumeClaim());

  assertEquals(
      podData.getSpec().getInitContainers().get(0).getVolumeMounts().get(0).getName(),
      "configMap");
  assertEquals(
      podData.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), "secret");
}