Search in sources :

Example 51 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class EnvVarsConverter method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    for (PodData pod : k8sEnv.getPodsData().values()) {
        for (Container container : pod.getSpec().getContainers()) {
            String machineName = Names.machineName(pod, container);
            InternalMachineConfig machineConf = k8sEnv.getMachines().get(machineName);
            // we need to combine the env vars from the machine config with the variables already
            // present in the container. Let's key the variables by name and use the map for merging
            Map<String, EnvVar> envVars = machineConf.getEnv().entrySet().stream().map(e -> new EnvVar(e.getKey(), e.getValue(), null)).collect(toMap(EnvVar::getName, identity()));
            // the env vars defined in our machine config take precedence over the ones already defined
            // in the container, if any
            container.getEnv().forEach(v -> envVars.putIfAbsent(v.getName(), v));
            // The environment variable expansion only works if a variable that is referenced
            // is already defined earlier in the list of environment variables.
            // We need to produce a list where variables that reference others always appear later
            // in the list.
            List<EnvVar> sorted = topoSort.sort(envVars.values());
            container.setEnv(sorted);
        }
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) MachineConfig(org.eclipse.che.api.core.model.workspace.config.MachineConfig) ConfigurationProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.ConfigurationProvisioner) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Singleton(javax.inject.Singleton) Traced(org.eclipse.che.commons.annotation.Traced) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) TopologicalSort(org.eclipse.che.commons.lang.TopologicalSort) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) Collectors.toMap(java.util.stream.Collectors.toMap) TracingTags(org.eclipse.che.commons.tracing.TracingTags) Map(java.util.Map) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Function.identity(java.util.function.Function.identity) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) 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) Function.identity(java.util.function.Function.identity) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Traced(org.eclipse.che.commons.annotation.Traced)

Example 52 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class RestartPolicyRewriter method provision.

@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId);
    for (PodData podConfig : k8sEnv.getPodsData().values()) {
        final String podName = podConfig.getMetadata().getName();
        final PodSpec podSpec = podConfig.getSpec();
        rewriteRestartPolicy(podSpec, podName, k8sEnv);
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Traced(org.eclipse.che.commons.annotation.Traced)

Example 53 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class OpenShiftInternalRuntime method createRoutes.

@Traced
// package-private so that interception is possible
@SuppressWarnings("WeakerAccess")
List<Route> createRoutes(OpenShiftEnvironment env, String workspaceId) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(workspaceId);
    Collection<Route> routesToCreate = env.getRoutes().values();
    List<Route> createdRoutes = new ArrayList<>(routesToCreate.size());
    for (Route route : routesToCreate) {
        createdRoutes.add(project.routes().create(route));
    }
    return createdRoutes;
}
Also used : ArrayList(java.util.ArrayList) Route(io.fabric8.openshift.api.model.Route) Traced(org.eclipse.che.commons.annotation.Traced)

Example 54 with Traced

use of org.eclipse.che.commons.annotation.Traced in project devspaces-images by redhat-developer.

the class OpenShiftInternalRuntime method createServices.

@Traced
// package-private so that interception is possible
@SuppressWarnings("WeakerAccess")
List<Service> createServices(OpenShiftEnvironment env, String workspaceId) throws InfrastructureException {
    TracingTags.WORKSPACE_ID.set(workspaceId);
    Collection<Service> servicesToCreate = env.getServices().values();
    List<Service> createdServices = new ArrayList<>(servicesToCreate.size());
    for (Service service : servicesToCreate) {
        createdServices.add(project.services().create(service));
    }
    return createdServices;
}
Also used : ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) Traced(org.eclipse.che.commons.annotation.Traced)

Aggregations

Traced (org.eclipse.che.commons.annotation.Traced)54 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)14 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)12 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 ArrayList (java.util.ArrayList)10 Service (io.fabric8.kubernetes.api.model.Service)8 Map (java.util.Map)8 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)8 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)8 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)8 Beta (com.google.common.annotations.Beta)6 Container (io.fabric8.kubernetes.api.model.Container)6 Route (io.fabric8.openshift.api.model.Route)6 ValidationException (org.eclipse.che.api.core.ValidationException)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4