Search in sources :

Example 51 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class BrokerEnvironmentFactory method getBrokersConfigs.

protected BrokersConfigs getBrokersConfigs(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, String brokerImage, boolean mergePlugins) throws InfrastructureException {
    String configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
    String configMapVolume = generateUniqueName(BROKER_VOLUME);
    ConfigMap configMap = newConfigMap(configMapName, pluginFQNs);
    Pod pod = newPod();
    List<EnvVar> envVars = Stream.of(authEnableEnvVarProvider.get(runtimeID), machineTokenEnvVarProvider.get(runtimeID)).map(this::asEnvVar).collect(Collectors.toList());
    Container container = newContainer(runtimeID, envVars, brokerImage, configMapVolume, mergePlugins);
    pod.getSpec().getContainers().add(container);
    pod.getSpec().getVolumes().add(newConfigMapVolume(configMapName, configMapVolume));
    InternalMachineConfig machineConfig = new InternalMachineConfig();
    String machineName = Names.machineName(pod.getMetadata(), container);
    BrokersConfigs configs = new BrokersConfigs();
    configs.configMaps = singletonMap(configMapName, configMap);
    configs.machines = singletonMap(machineName, machineConfig);
    configs.pods = singletonMap(pod.getMetadata().getName(), pod);
    return configs;
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 52 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class ServersConverter method provision.

@Override
@Traced
public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    SecureServerExposer<T> secureServerExposer = secureServerExposerFactoryProvider.get(k8sEnv).create(identity);
    for (PodData podConfig : k8sEnv.getPodsData().values()) {
        final PodSpec podSpec = podConfig.getSpec();
        for (Container containerConfig : podSpec.getContainers()) {
            String machineName = Names.machineName(podConfig, containerConfig);
            InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
            if (!machineConfig.getServers().isEmpty()) {
                KubernetesServerExposer kubernetesServerExposer = new KubernetesServerExposer<>(externalServerExposer, secureServerExposer, machineName, podConfig, containerConfig, k8sEnv);
                kubernetesServerExposer.expose(machineConfig.getServers());
            }
        }
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) KubernetesServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Traced(org.eclipse.che.commons.annotation.Traced)

Example 53 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class EnvVarsConverterTest method setUp.

@BeforeMethod
public void setUp() {
    testContainer = new Container();
    PodSpec podSpec = new PodSpec();
    podSpec.setContainers(singletonList(testContainer));
    ObjectMeta podMeta = new ObjectMeta();
    podMeta.setName("pod");
    Pod pod = new Pod();
    pod.setSpec(podSpec);
    pod.setMetadata(podMeta);
    Map<String, Pod> pods = new HashMap<>();
    pods.put("pod", pod);
    environment = KubernetesEnvironment.builder().setPods(pods).build();
    machine = new InternalMachineConfig();
    environment.setMachines(Collections.singletonMap(Names.machineName(podMeta, testContainer), machine));
    identity = new RuntimeIdentityImpl("wsId", "blah", "bleh", "infraNamespace");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) HashMap(java.util.HashMap) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 54 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class EnvironmentVariableSecretApplierTest method shouldProvisionContainersWithAutomountOverrideTrue.

@Test
public void shouldProvisionContainersWithAutomountOverrideTrue() throws Exception {
    Container container_match1 = new ContainerBuilder().withName("maven").build();
    Container container_match2 = new ContainerBuilder().withName("other").build();
    DevfileImpl mock_defvile = mock(DevfileImpl.class);
    ComponentImpl component = new ComponentImpl();
    component.setAlias("maven");
    component.setAutomountWorkspaceSecrets(true);
    when(podSpec.getContainers()).thenReturn(ImmutableList.of(container_match1, container_match2));
    InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
    internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
    when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
    when(environment.getDevfile()).thenReturn(mock_defvile);
    when(mock_defvile.getComponents()).thenReturn(singletonList(component));
    Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_ENV_NAME, "MY_FOO", ANNOTATION_MOUNT_AS, "env", ANNOTATION_AUTOMOUNT, "false")).withLabels(emptyMap()).build()).build();
    secretApplier.applySecret(environment, runtimeIdentity, secret);
    // only first container has env set
    assertEquals(container_match1.getEnv().size(), 1);
    EnvVar var = container_match1.getEnv().get(0);
    assertEquals(var.getName(), "MY_FOO");
    assertEquals(var.getValueFrom().getSecretKeyRef().getName(), "test_secret");
    assertEquals(var.getValueFrom().getSecretKeyRef().getKey(), "foo");
    assertEquals(container_match2.getEnv().size(), 0);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 55 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project che-server by eclipse-che.

the class BrokerEnvironmentFactory method getBrokersConfigs.

protected BrokersConfigs getBrokersConfigs(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID, String brokerImage, boolean mergePlugins) throws InfrastructureException {
    String configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
    String configMapVolume = generateUniqueName(BROKER_VOLUME);
    ConfigMap configMap = newConfigMap(configMapName, pluginFQNs);
    Pod pod = newPod();
    List<EnvVar> envVars = Stream.of(authEnableEnvVarProvider.get(runtimeID), machineTokenEnvVarProvider.get(runtimeID)).map(this::asEnvVar).collect(Collectors.toList());
    Container container = newContainer(runtimeID, envVars, brokerImage, configMapVolume, mergePlugins);
    pod.getSpec().getContainers().add(container);
    pod.getSpec().getVolumes().add(newConfigMapVolume(configMapName, configMapVolume));
    InternalMachineConfig machineConfig = new InternalMachineConfig();
    String machineName = Names.machineName(pod.getMetadata(), container);
    BrokersConfigs configs = new BrokersConfigs();
    configs.configMaps = singletonMap(configMapName, configMap);
    configs.machines = singletonMap(machineName, machineConfig);
    configs.pods = singletonMap(pod.getMetadata().getName(), pod);
    return configs;
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Aggregations

InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)88 Test (org.testng.annotations.Test)64 Container (io.fabric8.kubernetes.api.model.Container)36 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)18 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)16 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)12 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)12 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)12 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 Pod (io.fabric8.kubernetes.api.model.Pod)10 Secret (io.fabric8.kubernetes.api.model.Secret)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)10 HashMap (java.util.HashMap)8 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)8 Traced (org.eclipse.che.commons.annotation.Traced)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)6