use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class OpenShiftEnvironmentFactoryTest method shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing.
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
// given
PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment-test").endMetadata().withNewSpec().withTemplate(podTemplate).endSpec().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));
// when
final KubernetesEnvironment k8sEnv = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
// then
Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
assertNotNull(deploymentTest);
PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class OpenShiftEnvironmentFactoryTest method addConfigMapsWhenRecipeContainsThem.
@Test
public void addConfigMapsWhenRecipeContainsThem() throws Exception {
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("test-configmap").endMetadata().build();
when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(configMap));
final KubernetesEnvironment parsed = osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());
assertEquals(parsed.getConfigMaps().size(), 1);
assertEquals(parsed.getConfigMaps().values().iterator().next().getMetadata().getName(), configMap.getMetadata().getName());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class WsMasterModule method installDefaultSecureServerExposer.
private void installDefaultSecureServerExposer(String infrastructure) {
if (KubernetesInfrastructure.NAME.equals(infrastructure)) {
MapBinder<String, SecureServerExposerFactory<KubernetesEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
}, new TypeLiteral<>() {
});
install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<KubernetesEnvironment>>() {
}, new TypeLiteral<PassThroughProxySecureServerExposer<KubernetesEnvironment>>() {
}).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
}));
secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
});
} else {
MapBinder<String, SecureServerExposerFactory<OpenShiftEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
}, new TypeLiteral<>() {
});
install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<OpenShiftEnvironment>>() {
}, new TypeLiteral<PassThroughProxySecureServerExposer<OpenShiftEnvironment>>() {
}).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
}));
secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
});
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method doStartMachine.
/**
* Creates Kubernetes pods and resolves servers using the specified serverResolver.
*
* @param serverResolver server resolver that provide servers by container
* @throws InfrastructureException when any error occurs while creating Kubernetes pods
*/
@Traced
protected void doStartMachine(ServerResolver serverResolver) throws InfrastructureException {
final KubernetesEnvironment environment = getContext().getEnvironment();
final Map<String, InternalMachineConfig> machineConfigs = environment.getMachines();
final String workspaceId = getContext().getIdentity().getWorkspaceId();
LOG.debug("Begin pods creation for workspace '{}'", workspaceId);
PodMerger podMerger = new PodMerger();
Map<String, Map<String, Pod>> injectablePods = environment.getInjectablePodsCopy();
for (Pod toCreate : environment.getPodsCopy().values()) {
ObjectMeta toCreateMeta = toCreate.getMetadata();
List<PodData> injectables = getAllInjectablePods(toCreate, injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment merged = podMerger.merge(injectables);
merged.getMetadata().setName(toCreate.getMetadata().getName());
createdPod = namespace.deployments().deploy(merged);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating pod '{}' in workspace '{}'", toCreateMeta.getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
for (Deployment toCreate : environment.getDeploymentsCopy().values()) {
PodTemplateSpec template = toCreate.getSpec().getTemplate();
List<PodData> injectables = getAllInjectablePods(template.getMetadata(), template.getSpec().getContainers(), injectablePods);
Pod createdPod;
if (injectables.isEmpty()) {
createdPod = namespace.deployments().deploy(toCreate);
} else {
try {
injectables.add(new PodData(toCreate));
Deployment deployment = podMerger.merge(injectables);
deployment.getMetadata().setName(toCreate.getMetadata().getName());
putAnnotations(deployment.getMetadata(), toCreate.getMetadata().getAnnotations());
putLabels(deployment.getMetadata(), toCreate.getMetadata().getLabels());
createdPod = namespace.deployments().deploy(deployment);
} catch (ValidationException e) {
throw new InfrastructureException(e);
}
}
LOG.debug("Creating deployment '{}' in workspace '{}'", createdPod.getMetadata().getName(), workspaceId);
storeStartingMachine(createdPod, createdPod.getMetadata(), machineConfigs, serverResolver);
}
LOG.debug("Pods creation finished in workspace '{}'", workspaceId);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method startMachines.
/**
* Create all machine related objects and start machines.
*
* @throws InfrastructureException when any error occurs while creating Kubernetes objects
*/
@Traced
protected void startMachines() throws InfrastructureException {
KubernetesEnvironment k8sEnv = getContext().getEnvironment();
String workspaceId = getContext().getIdentity().getWorkspaceId();
createSecrets(k8sEnv, workspaceId);
List<ConfigMap> createdConfigMaps = createConfigMaps(k8sEnv, getContext().getIdentity());
List<Service> createdServices = createServices(k8sEnv, workspaceId);
// needed for resolution later on, even though n routes are actually created by ingress
// /workspace{wsid}/server-{port} => service({wsid}):server-port => pod({wsid}):{port}
List<Ingress> readyIngresses = createIngresses(k8sEnv, workspaceId);
listenEvents();
doStartMachine(serverResolverFactory.create(createdServices, readyIngresses, createdConfigMaps));
}
Aggregations