use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class ServiceAccountProvisioner method provision.
@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
if (!isNullOrEmpty(serviceAccount)) {
for (PodData pod : k8sEnv.getPodsData().values()) {
pod.getSpec().setServiceAccountName(serviceAccount);
pod.getSpec().setAutomountServiceAccountToken(true);
}
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class UniqueNamesProvisioner method rewriteConfigMapNames.
private void rewriteConfigMapNames(PodData pod, Map<String, String> configMapNameTranslation) {
// First update any env vars that reference configMaps.
for (Container container : pod.getSpec().getContainers()) {
// Can set env vars to key/value pairs in configmap
if (container.getEnv() != null) {
container.getEnv().stream().filter(env -> env.getValueFrom() != null && env.getValueFrom().getConfigMapKeyRef() != null).forEach(env -> {
ConfigMapKeySelector configMap = env.getValueFrom().getConfigMapKeyRef();
String originalName = configMap.getName();
// null).
if (configMapNameTranslation.containsKey(originalName)) {
configMap.setName(configMapNameTranslation.get(originalName));
}
});
}
if (container.getEnvFrom() != null) {
// Can use all entries in configMap as env vars
container.getEnvFrom().stream().filter(envFrom -> envFrom.getConfigMapRef() != null).forEach(envFrom -> {
ConfigMapEnvSource configMapRef = envFrom.getConfigMapRef();
String originalName = configMapRef.getName();
if (configMapNameTranslation.containsKey(originalName)) {
configMapRef.setName(configMapNameTranslation.get(originalName));
}
});
}
}
// Next update any mounted configMaps
List<Volume> volumes = pod.getSpec().getVolumes();
if (pod.getSpec().getVolumes() != null) {
volumes.stream().filter(vol -> vol.getConfigMap() != null).forEach(volume -> {
ConfigMapVolumeSource configMapVolume = volume.getConfigMap();
String originalName = configMapVolume.getName();
if (configMapNameTranslation.containsKey(originalName)) {
configMapVolume.setName(configMapNameTranslation.get(originalName));
}
});
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class KubernetesTrustedCAProvisioner method provision.
/**
* Propagates additional CA certificates into config map and mounts them into all pods of given
* namespace
*
* @param k8sEnv available objects in the scope
* @param runtimeID defines namespace into which config map should be provisioned
* @throws InfrastructureException if failed to CRUD a resource
*/
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity runtimeID) throws InfrastructureException {
if (!trustedStoreInitialized) {
return;
}
ConfigMap allCaCertsConfigMap = cheServerClientFactory.create().configMaps().inNamespace(installationLocationNamespace).withName(caBundleConfigMap).get();
if (allCaCertsConfigMap == null) {
return;
}
k8sEnv.getConfigMaps().put(configMapName, new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName(configMapName).withAnnotations(allCaCertsConfigMap.getMetadata().getAnnotations()).withLabels(configMapLabelKeyValue).build()).withApiVersion(allCaCertsConfigMap.getApiVersion()).withData(allCaCertsConfigMap.getData()).build());
for (PodData pod : k8sEnv.getPodsData().values()) {
if (pod.getRole() == PodRole.DEPLOYMENT) {
if (pod.getSpec().getVolumes().stream().noneMatch(v -> v.getName().equals(CHE_TRUST_STORE_VOLUME))) {
pod.getSpec().getVolumes().add(new VolumeBuilder().withName(CHE_TRUST_STORE_VOLUME).withConfigMap(new ConfigMapVolumeSourceBuilder().withName(configMapName).build()).build());
}
}
for (Container container : pod.getSpec().getInitContainers()) {
provisionTrustStoreVolumeMountIfNeeded(container);
}
for (Container container : pod.getSpec().getContainers()) {
provisionTrustStoreVolumeMountIfNeeded(container);
}
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class OpenShiftUniqueNamesProvisionerTest method provideUniquePodsNames.
@Test
public void provideUniquePodsNames() throws Exception {
when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
Pod pod = newPod();
PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
doReturn(ImmutableMap.of(POD_NAME, podData)).when(osEnv).getPodsData();
uniqueNamesProvisioner.provision(osEnv, runtimeIdentity);
ObjectMeta podMetadata = pod.getMetadata();
assertNotEquals(podMetadata.getName(), POD_NAME);
assertEquals(podMetadata.getLabels().get(CHE_ORIGINAL_NAME_LABEL), POD_NAME);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method prepareMachineConfigs.
/**
* Creates map of machine names and corresponding {@link MachineConfigImpl} with component alias
* attribute set.
*/
private Map<String, MachineConfigImpl> prepareMachineConfigs(List<PodData> podsData, ComponentImpl component) throws DevfileException {
Map<String, MachineConfigImpl> machineConfigs = new HashMap<>();
for (PodData podData : podsData) {
List<Container> containers = new ArrayList<>();
containers.addAll(podData.getSpec().getContainers());
containers.addAll(podData.getSpec().getInitContainers());
for (Container container : containers) {
String machineName = machineName(podData, container);
MachineConfigImpl config = new MachineConfigImpl();
if (!isNullOrEmpty(component.getAlias())) {
config.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, component.getAlias());
}
provisionVolumes(component, container, config);
provisionEndpoints(component, config);
machineConfigs.put(machineName, config);
}
}
return machineConfigs;
}
Aggregations