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

The following examples show how to use io.fabric8.kubernetes.api.model.EnvFromSourceBuilder. 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: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void rewritePodConfigMapEnvFrom() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  ConfigMap configMap = newConfigMap();
  doReturn(ImmutableMap.of(CONFIGMAP_NAME, configMap)).when(k8sEnv).getConfigMaps();

  EnvFromSource envFrom =
      new EnvFromSourceBuilder()
          .withNewConfigMapRef()
          .withName(CONFIGMAP_NAME)
          .endConfigMapRef()
          .build();
  Container container = new ContainerBuilder().withEnvFrom(envFrom).build();
  Pod pod = newPod();
  pod.getSpec().setContainers(ImmutableList.of(container));
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  String newConfigMapName = configMap.getMetadata().getName();
  EnvFromSource newEnvFromSource = container.getEnvFrom().iterator().next();
  assertEquals(newEnvFromSource.getConfigMapRef().getName(), newConfigMapName);
}
 
Example #2
Source File: UniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void doesNotRewritePodConfigMapEnvFromWhenNoConfigMap() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);

  EnvFromSource envFrom =
      new EnvFromSourceBuilder()
          .withNewConfigMapRef()
          .withName(CONFIGMAP_NAME)
          .endConfigMapRef()
          .build();
  Container container = new ContainerBuilder().withEnvFrom(envFrom).build();
  Pod pod = newPod();
  pod.getSpec().setContainers(ImmutableList.of(container));
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(k8sEnv).getPodsData();

  uniqueNamesProvisioner.provision(k8sEnv, runtimeIdentity);

  EnvFromSource newEnvFromSource = container.getEnvFrom().iterator().next();
  assertEquals(newEnvFromSource.getConfigMapRef().getName(), CONFIGMAP_NAME);
}
 
Example #3
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 4 votes vote down vote up
private static Deployment getPostgresDeployment() {
    return new DeploymentBuilder()
            .withNewMetadata()
            .withName(POSTGRES_APP)
            .addToLabels("app", POSTGRES_APP)
            .addToLabels("template", POSTGRES_APP)
            .endMetadata()
            .withNewSpec()
            .withNewSelector()
            .addToMatchLabels("app", POSTGRES_APP)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
            .withNewMetadata()
            .addToLabels("app", POSTGRES_APP)
            .endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName(POSTGRES_APP)
            .withImage("postgres:10.4")
            .withImagePullPolicy("IfNotPresent")
            .addNewPort()
            .withContainerPort(5432)
            .endPort()
            .withEnvFrom(new EnvFromSourceBuilder()
                    .withNewConfigMapRef()
                    .withName(POSTGRES_APP)
                    .endConfigMapRef()
                    .build())
            .withVolumeMounts(new VolumeMountBuilder()
                    .withMountPath("/var/lib/postgresql/data/")
                    .withName(POSTGRES_APP).build())
            .endContainer()
            .addNewVolume()
            .withName(POSTGRES_APP)
            .withNewPersistentVolumeClaim()
            .withClaimName(POSTGRES_APP)
            .endPersistentVolumeClaim()
            .endVolume()
            .endSpec()
            .endTemplate()
            .endSpec()
            .build();
}