use of io.fabric8.kubernetes.api.model.EnvFromSource in project che-server by eclipse-che.
the class UniqueNamesProvisionerTest method rewritePodConfigMapEnvFrom.
@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);
}
use of io.fabric8.kubernetes.api.model.EnvFromSource in project devspaces-images by redhat-developer.
the class UniqueNamesProvisionerTest method rewritePodConfigMapEnvFrom.
@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);
}
use of io.fabric8.kubernetes.api.model.EnvFromSource in project quarkus by quarkusio.
the class KubernetesWithMixedStyleEnvTest method assertGeneratedResources.
@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> {
assertThat(d.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo(APPLICATION_NAME);
});
assertThat(d.getSpec()).satisfies(deploymentSpec -> {
assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
assertThat(t.getSpec()).satisfies(podSpec -> {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
assertThat(container.getEnv()).filteredOn(env -> "FROMFIELD".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValueFrom().getFieldRef().getFieldPath()).isEqualTo("metadata.name"));
assertThat(container.getEnv()).filteredOn(env -> "ENVVAR".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("value"));
final List<EnvFromSource> envFrom = container.getEnvFrom();
assertThat(envFrom).hasSize(2);
assertThat(envFrom).filteredOn(e -> e.getSecretRef() != null).singleElement().satisfies(e -> assertThat(e.getSecretRef().getName()).isEqualTo("secretName"));
assertThat(envFrom).filteredOn(e -> e.getConfigMapRef() != null).singleElement().satisfies(e -> assertThat(e.getConfigMapRef().getName()).isEqualTo("configName"));
});
});
});
});
});
}
use of io.fabric8.kubernetes.api.model.EnvFromSource in project quarkus by quarkusio.
the class KubernetesWithNewStyleEnvTest method assertGeneratedResources.
@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")).isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> {
assertThat(d.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo(APPLICATION_NAME);
});
assertThat(d.getSpec()).satisfies(deploymentSpec -> {
assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
assertThat(t.getSpec()).satisfies(podSpec -> {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
assertThat(container.getEnv()).filteredOn(env -> "FROMFIELD".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValueFrom().getFieldRef().getFieldPath()).isEqualTo("metadata.name"));
assertThat(container.getEnv()).filteredOn(env -> "ENVVAR".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("value"));
assertThat(container.getEnv()).filteredOn(env -> "QUARKUS_KUBERNETES_CONFIG_ENABLED".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("true"));
assertThat(container.getEnv()).filteredOn(env -> "FOO_MP_REST_URL".equals(env.getName())).singleElement().satisfies(env -> assertThat(env.getValue()).isEqualTo("foo.url"));
final List<EnvFromSource> envFrom = container.getEnvFrom();
assertThat(envFrom).hasSize(2);
assertThat(envFrom).filteredOn(e -> e.getSecretRef() != null).singleElement().satisfies(e -> assertThat(e.getSecretRef().getName()).isEqualTo("secretName"));
assertThat(envFrom).filteredOn(e -> e.getConfigMapRef() != null).singleElement().satisfies(e -> assertThat(e.getConfigMapRef().getName()).isEqualTo("configName"));
});
});
});
});
});
}
use of io.fabric8.kubernetes.api.model.EnvFromSource in project stackgres by ongres.
the class DistributedLogsRequiredResourcesGeneratorTest method get095Sts.
@NotNull
private StatefulSet get095Sts(StackGresDistributedLogs distributedLogs095) {
StatefulSet sts = JsonUtil.readFromJson("statefulset/0.9.5-distributedlogs.json", StatefulSet.class);
final String namespace = distributedLogs095.getMetadata().getNamespace();
sts.getMetadata().setNamespace(namespace);
final String distributedLogsName = distributedLogs095.getMetadata().getName();
sts.getMetadata().setName(distributedLogsName);
final String uid = distributedLogs095.getMetadata().getUid();
fix095Labels(sts, distributedLogs095);
fix095Labels(sts.getSpec().getTemplate().getMetadata(), distributedLogs095);
fix095Labels(sts.getSpec().getSelector().getMatchLabels(), distributedLogs095);
Container patroniContainer = sts.getSpec().getTemplate().getSpec().getContainers().get(0);
patroniContainer.getEnv().forEach(envVar -> {
Optional.ofNullable(envVar.getValueFrom()).map(EnvVarSource::getSecretKeyRef).filter(secretKeySelector -> secretKeySelector.getName().equals("distributedlogs")).ifPresent(secretKeySelector -> secretKeySelector.setName(distributedLogsName));
Optional.ofNullable(envVar.getValueFrom()).map(EnvVarSource::getConfigMapKeyRef).filter(configMapKeySelector -> configMapKeySelector.getName().equals("distributedlogs")).ifPresent(configMapKeySelector -> configMapKeySelector.setName(distributedLogsName));
});
patroniContainer.getEnvFrom().stream().map(EnvFromSource::getConfigMapRef).forEach(configMapEnvSource -> configMapEnvSource.setName(distributedLogsName));
final List<Container> containers = sts.getSpec().getTemplate().getSpec().getContainers();
final List<Container> initContainers = sts.getSpec().getTemplate().getSpec().getInitContainers();
var allContainers = Stream.concat(containers.stream(), initContainers.stream());
allContainers.forEach(container -> container.getVolumeMounts().stream().filter(volumeMount -> volumeMount.getName().startsWith("distributedlogs")).forEach(volumeMount -> {
String name = volumeMount.getName().replaceAll("distributedlogs", distributedLogsName);
volumeMount.setName(name);
}));
final List<OwnerReference> ownerReferences = List.of(new OwnerReferenceBuilder().withApiVersion(CommonDefinition.GROUP + "/v1beta1").withKind(distributedLogs095.getKind()).withName(distributedLogsName).withUid(uid).withController(true).build());
sts.getMetadata().setOwnerReferences(ownerReferences);
sts.getSpec().setServiceName(distributedLogsName);
sts.getSpec().getTemplate().getSpec().setServiceAccount(distributedLogsName + "-patroni");
sts.getSpec().getTemplate().getSpec().setServiceAccountName(distributedLogsName + "-patroni");
sts.getSpec().getTemplate().getSpec().getVolumes().stream().filter(volume -> volume.getName().startsWith("distributedlogs")).forEach(volume -> {
String name = volume.getName().replaceAll("distributedlogs", distributedLogsName);
volume.setName(name);
});
sts.getSpec().getTemplate().getSpec().getVolumes().stream().map(Volume::getConfigMap).filter(Objects::nonNull).forEach(configMap -> {
String configMapName = configMap.getName().replaceAll("distributedlogs", distributedLogsName);
configMap.setName(configMapName);
});
sts.getSpec().getVolumeClaimTemplates().forEach(vct -> {
fix095Labels(vct, distributedLogs095);
vct.getMetadata().setName(distributedLogsName + "-data");
vct.getMetadata().setNamespace(namespace);
vct.getMetadata().setOwnerReferences(ownerReferences);
});
return sts;
}
Aggregations