Search in sources :

Example 36 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class KubernetesInfraModule method configure.

@Override
protected void configure() {
    Multibinder<WorkspaceAttributeValidator> workspaceAttributeValidators = Multibinder.newSetBinder(binder(), WorkspaceAttributeValidator.class);
    workspaceAttributeValidators.addBinding().to(K8sInfraNamespaceWsAttributeValidator.class);
    workspaceAttributeValidators.addBinding().to(AsyncStorageModeValidator.class);
    // order matters here!
    // We first need to grant permissions to user, only then we can run other configurators with
    // user's client.
    Multibinder<NamespaceConfigurator> namespaceConfigurators = Multibinder.newSetBinder(binder(), NamespaceConfigurator.class);
    namespaceConfigurators.addBinding().to(UserPermissionConfigurator.class);
    namespaceConfigurators.addBinding().to(CredentialsSecretConfigurator.class);
    namespaceConfigurators.addBinding().to(PreferencesConfigMapConfigurator.class);
    namespaceConfigurators.addBinding().to(WorkspaceServiceAccountConfigurator.class);
    namespaceConfigurators.addBinding().to(UserProfileConfigurator.class);
    namespaceConfigurators.addBinding().to(UserPreferencesConfigurator.class);
    namespaceConfigurators.addBinding().to(SshKeysConfigurator.class);
    bind(KubernetesNamespaceService.class);
    MapBinder<String, InternalEnvironmentFactory> factories = MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
    factories.addBinding(KubernetesEnvironment.TYPE).to(KubernetesEnvironmentFactory.class);
    factories.addBinding(Constants.NO_ENVIRONMENT_RECIPE_TYPE).to(NoEnvironmentFactory.class);
    bind(RuntimeInfrastructure.class).to(KubernetesInfrastructure.class);
    bind(InconsistentRuntimesDetector.class).asEagerSingleton();
    bind(TrustedCAProvisioner.class).to(KubernetesTrustedCAProvisioner.class);
    MapBinder<WorkspaceExposureType, TlsProvisioner<KubernetesEnvironment>> tlsProvisioners = MapBinder.newMapBinder(binder(), new TypeLiteral<WorkspaceExposureType>() {
    }, new TypeLiteral<TlsProvisioner<KubernetesEnvironment>>() {
    });
    tlsProvisioners.addBinding(WorkspaceExposureType.GATEWAY).to(new TypeLiteral<GatewayTlsProvisioner<KubernetesEnvironment>>() {
    });
    tlsProvisioners.addBinding(WorkspaceExposureType.NATIVE).to(IngressTlsProvisioner.class);
    bind(new TypeLiteral<KubernetesEnvironmentProvisioner<KubernetesEnvironment>>() {
    }).to(KubernetesEnvironmentProvisioner.KubernetesEnvironmentProvisionerImpl.class);
    install(new FactoryModuleBuilder().build(KubernetesRuntimeContextFactory.class));
    install(new FactoryModuleBuilder().build(new TypeLiteral<KubernetesRuntimeFactory<KubernetesEnvironment>>() {
    }));
    install(new FactoryModuleBuilder().build(StartSynchronizerFactory.class));
    bind(WorkspacePVCCleaner.class).asEagerSingleton();
    bind(RemoveNamespaceOnWorkspaceRemove.class).asEagerSingleton();
    bind(CheApiInternalEnvVarProvider.class).to(KubernetesCheApiInternalEnvVarProvider.class);
    bind(CheApiExternalEnvVarProvider.class).to(KubernetesCheApiExternalEnvVarProvider.class);
    MapBinder<String, WorkspaceVolumesStrategy> volumesStrategies = MapBinder.newMapBinder(binder(), String.class, WorkspaceVolumesStrategy.class);
    volumesStrategies.addBinding(COMMON_STRATEGY).to(CommonPVCStrategy.class);
    volumesStrategies.addBinding(PER_WORKSPACE_STRATEGY).to(PerWorkspacePVCStrategy.class);
    volumesStrategies.addBinding(UNIQUE_STRATEGY).to(UniqueWorkspacePVCStrategy.class);
    bind(WorkspaceVolumesStrategy.class).toProvider(WorkspaceVolumeStrategyProvider.class);
    Multibinder.newSetBinder(binder(), ServiceTermination.class).addBinding().to(KubernetesClientTermination.class);
    MapBinder<String, ExternalServiceExposureStrategy> ingressStrategies = MapBinder.newMapBinder(binder(), String.class, ExternalServiceExposureStrategy.class);
    ingressStrategies.addBinding(MULTI_HOST_STRATEGY).to(MultiHostExternalServiceExposureStrategy.class);
    ingressStrategies.addBinding(SINGLE_HOST_STRATEGY).to(SingleHostExternalServiceExposureStrategy.class);
    ingressStrategies.addBinding(DEFAULT_HOST_STRATEGY).to(DefaultHostExternalServiceExposureStrategy.class);
    bind(ExternalServiceExposureStrategy.class).toProvider(ServiceExposureStrategyProvider.class);
    MapBinder<WorkspaceExposureType, ExternalServerExposer<KubernetesEnvironment>> exposureStrategies = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
    }, new TypeLiteral<>() {
    });
    exposureStrategies.addBinding(WorkspaceExposureType.NATIVE).to(new TypeLiteral<IngressServerExposer<KubernetesEnvironment>>() {
    });
    exposureStrategies.addBinding(WorkspaceExposureType.GATEWAY).to(new TypeLiteral<GatewayServerExposer<KubernetesEnvironment>>() {
    });
    bind(new TypeLiteral<ExternalServerExposer<KubernetesEnvironment>>() {
    }).annotatedWith(com.google.inject.name.Names.named("multihost-exposer")).to(new TypeLiteral<MultihostIngressServerExposer<KubernetesEnvironment>>() {
    });
    bind(new TypeLiteral<ExternalServerExposerProvider<KubernetesEnvironment>>() {
    }).to(new TypeLiteral<KubernetesExternalServerExposerProvider<KubernetesEnvironment>>() {
    });
    bind(ServersConverter.class).to(new TypeLiteral<ServersConverter<KubernetesEnvironment>>() {
    });
    bind(PreviewUrlExposer.class).to(new TypeLiteral<PreviewUrlExposer<KubernetesEnvironment>>() {
    });
    bind(PreviewUrlCommandProvisioner.class).to(new TypeLiteral<KubernetesPreviewUrlCommandProvisioner>() {
    });
    Multibinder<EnvVarProvider> envVarProviders = Multibinder.newSetBinder(binder(), EnvVarProvider.class);
    envVarProviders.addBinding().to(LogsRootEnvVariableProvider.class);
    bind(new TypeLiteral<Map<String, String>>() {
    }).annotatedWith(named("infra.kubernetes.ingress.annotations")).toProvider(IngressAnnotationsProvider.class);
    install(new JpaKubernetesRuntimeCacheModule());
    bind(SecureServerExposerFactoryProvider.class).to(new TypeLiteral<SecureServerExposerFactoryProvider<KubernetesEnvironment>>() {
    });
    MapBinder<String, ChePluginsApplier> chePluginsAppliers = MapBinder.newMapBinder(binder(), String.class, ChePluginsApplier.class);
    chePluginsAppliers.addBinding(KubernetesEnvironment.TYPE).to(KubernetesPluginsToolingApplier.class);
    bind(BrokerService.class);
    bind(new TypeLiteral<BrokerEnvironmentFactory<KubernetesEnvironment>>() {
    }).to(KubernetesBrokerEnvironmentFactory.class);
    bind(PluginBrokerManager.class).to(new TypeLiteral<PluginBrokerManager<KubernetesEnvironment>>() {
    });
    bind(SidecarToolingProvisioner.class).to(new TypeLiteral<SidecarToolingProvisioner<KubernetesEnvironment>>() {
    });
    DevfileBindings.onComponentIntegrityValidatorBinder(binder(), binder -> {
        binder.addBinding(KUBERNETES_COMPONENT_TYPE).to(KubernetesComponentValidator.class);
        binder.addBinding(DOCKERIMAGE_COMPONENT_TYPE).to(NoopComponentIntegrityValidator.class);
    });
    DevfileBindings.onWorkspaceApplierBinder(binder(), binder -> {
        binder.addBinding(KUBERNETES_COMPONENT_TYPE).to(KubernetesComponentToWorkspaceApplier.class);
        binder.addBinding(DOCKERIMAGE_COMPONENT_TYPE).to(DockerimageComponentToWorkspaceApplier.class);
    });
    KubernetesDevfileBindings.addKubernetesBasedEnvironmentTypeBindings(binder(), KubernetesEnvironment.TYPE);
    KubernetesDevfileBindings.addKubernetesBasedComponentTypeBindings(binder(), KUBERNETES_COMPONENT_TYPE);
    // We need to initialize the bindings somehow. Because no other environment type is upgradable
    // to kubernetes, we just call this in a way that initializes the binding with an empty map.
    KubernetesDevfileBindings.addAllowedEnvironmentTypeUpgradeBindings(binder(), KubernetesEnvironment.TYPE);
    bind(NonTlsDistributedClusterModeNotifier.class);
    bind(AsyncStorageProvisioner.class);
}
Also used : PreviewUrlExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.PreviewUrlExposer) CheApiExternalEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider) KubernetesCheApiExternalEnvVarProvider(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiExternalEnvVarProvider) KubernetesPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesPreviewUrlCommandProvisioner) KubernetesPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesPreviewUrlCommandProvisioner) PreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.PreviewUrlCommandProvisioner) SingleHostExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy) MultiHostExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy) DefaultHostExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.DefaultHostExternalServiceExposureStrategy) ExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServiceExposureStrategy) ServersConverter(org.eclipse.che.workspace.infrastructure.kubernetes.provision.server.ServersConverter) GatewayTlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.GatewayTlsProvisioner) MultihostIngressServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultihostIngressServerExposer) WorkspacePVCCleaner(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspacePVCCleaner) CheApiInternalEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider) KubernetesCheApiInternalEnvVarProvider(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiInternalEnvVarProvider) GatewayServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayServerExposer) CheApiExternalEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider) EnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.EnvVarProvider) CheApiInternalEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider) KubernetesCheApiExternalEnvVarProvider(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiExternalEnvVarProvider) KubernetesCheApiInternalEnvVarProvider(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiInternalEnvVarProvider) Map(java.util.Map) RuntimeInfrastructure(org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure) NamespaceConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator) TlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TlsProvisioner) IngressTlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.IngressTlsProvisioner) GatewayTlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.GatewayTlsProvisioner) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) WorkspaceExposureType(org.eclipse.che.workspace.infrastructure.kubernetes.server.WorkspaceExposureType) SidecarToolingProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner) SecureServerExposerFactoryProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactoryProvider) TypeLiteral(com.google.inject.TypeLiteral) JpaKubernetesRuntimeCacheModule(org.eclipse.che.workspace.infrastructure.kubernetes.cache.jpa.JpaKubernetesRuntimeCacheModule) ExternalServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer) ChePluginsApplier(org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier) RemoveNamespaceOnWorkspaceRemove(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.RemoveNamespaceOnWorkspaceRemove) WorkspaceVolumesStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy) WorkspaceAttributeValidator(org.eclipse.che.api.workspace.server.WorkspaceAttributeValidator) InternalEnvironmentFactory(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory) PluginBrokerManager(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.PluginBrokerManager) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) KubernetesExternalServerExposerProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.KubernetesExternalServerExposerProvider) IngressServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressServerExposer) MultihostIngressServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultihostIngressServerExposer) KubernetesTrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesTrustedCAProvisioner) TrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TrustedCAProvisioner)

Example 37 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class CommonPVCStrategy method prepare.

@Override
@Traced
public void prepare(KubernetesEnvironment k8sEnv, RuntimeIdentity identity, long timeoutMillis, Map<String, String> startOptions) throws InfrastructureException {
    String workspaceId = identity.getWorkspaceId();
    TracingTags.WORKSPACE_ID.set(workspaceId);
    if (EphemeralWorkspaceUtility.isEphemeral(k8sEnv.getAttributes())) {
        return;
    }
    log.debug("Preparing PVC started for workspace '{}'", workspaceId);
    Map<String, PersistentVolumeClaim> claims = k8sEnv.getPersistentVolumeClaims();
    if (claims.isEmpty()) {
        return;
    }
    if (claims.size() > 1) {
        throw new InfrastructureException(format("The only one PVC MUST be present in common strategy while it contains: %s.", claims.keySet().stream().collect(joining(", "))));
    }
    PersistentVolumeClaim commonPVC = claims.values().iterator().next();
    final KubernetesNamespace namespace = factory.getOrCreate(identity);
    final KubernetesPersistentVolumeClaims pvcs = namespace.persistentVolumeClaims();
    final Set<String> existing = pvcs.get().stream().map(p -> p.getMetadata().getName()).collect(toSet());
    if (!existing.contains(commonPVC.getMetadata().getName())) {
        log.debug("Creating PVC for workspace '{}'", workspaceId);
        pvcs.create(commonPVC);
        if (waitBound) {
            log.debug("Waiting for PVC for workspace '{}' to be bound", workspaceId);
            pvcs.waitBound(commonPVC.getMetadata().getName(), timeoutMillis);
        }
    }
    final String[] subpaths = (String[]) commonPVC.getAdditionalProperties().remove(format(SUBPATHS_PROPERTY_FMT, workspaceId));
    if (preCreateDirs && subpaths != null) {
        pvcSubPathHelper.createDirs(identity, workspaceId, commonPVC.getMetadata().getName(), startOptions, subpaths);
    }
    log.debug("Preparing PVC done for workspace '{}'", workspaceId);
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) PERSONAL_ACCOUNT(org.eclipse.che.api.user.server.UserManager.PERSONAL_ACCOUNT) Inject(com.google.inject.Inject) Page(org.eclipse.che.api.core.Page) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Traced(org.eclipse.che.commons.annotation.Traced) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Map(java.util.Map) Named(javax.inject.Named) Collectors.toSet(java.util.stream.Collectors.toSet) KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) Logger(org.slf4j.Logger) Set(java.util.Set) KubernetesPersistentVolumeClaims(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesPersistentVolumeClaims) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) KubernetesNamespaceFactory(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) ServerException(org.eclipse.che.api.core.ServerException) TracingTags(org.eclipse.che.commons.tracing.TracingTags) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesPersistentVolumeClaims(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesPersistentVolumeClaims) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Traced(org.eclipse.che.commons.annotation.Traced)

Example 38 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class EphemeralWorkspaceAdapter method replacePVCsWithEmptyDir.

private void replacePVCsWithEmptyDir(KubernetesEnvironment k8sEnv) {
    for (PodData pod : k8sEnv.getPodsData().values()) {
        PodSpec podSpec = pod.getSpec();
        podSpec.getVolumes().stream().filter(v -> v.getPersistentVolumeClaim() != null).forEach(v -> {
            v.setPersistentVolumeClaim(null);
            v.setEmptyDir(new EmptyDirVolumeSource());
        });
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) EmptyDirVolumeSource(io.fabric8.kubernetes.api.model.EmptyDirVolumeSource) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Map(java.util.Map) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) EmptyDirVolumeSource(io.fabric8.kubernetes.api.model.EmptyDirVolumeSource) PodSpec(io.fabric8.kubernetes.api.model.PodSpec)

Example 39 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class KubernetesArtifactsBrokerApplierTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    // Workspace env setup
    ObjectMeta workspacePodMeta = new ObjectMetaBuilder().withAnnotations(workspacePodAnnotations).build();
    workspacePod = new PodBuilder().withMetadata(workspacePodMeta).withSpec(new PodSpec()).build();
    Map<String, ConfigMap> workspaceConfigMaps = new HashMap<>();
    workspaceEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of(WORKSPACE_POD_NAME, workspacePod)).setMachines(new HashMap<>()).setConfigMaps(workspaceConfigMaps).build();
    // Broker env setup
    ObjectMeta brokerPodMeta = new ObjectMetaBuilder().withAnnotations(brokerPodAnnotations).build();
    brokerContainer = new ContainerBuilder().withName(BROKER_CONTAINER_NAME).build();
    brokerVolume = new VolumeBuilder().build();
    Pod brokerPod = new PodBuilder().withMetadata(brokerPodMeta).withNewSpec().withContainers(brokerContainer).withVolumes(brokerVolume).endSpec().build();
    brokerConfigMap = new ConfigMapBuilder().addToData(brokerConfigMapData).build();
    KubernetesEnvironment brokerEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of(BROKER_POD_NAME, brokerPod)).setConfigMaps(ImmutableMap.of(BROKER_CONFIGMAP_NAME, brokerConfigMap)).setMachines(ImmutableMap.of(BROKER_MACHINE_NAME, brokerMachine)).build();
    doReturn(brokerEnvironment).when(brokerEnvironmentFactory).createForArtifactsBroker(any(), any(), anyBoolean());
    applier = new KubernetesArtifactsBrokerApplier<>(brokerEnvironmentFactory);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) HashMap(java.util.HashMap) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplier method addSidecar.

/**
 * Adds k8s and Che specific configuration of a sidecar into the environment. For example:
 * <li>k8s container configuration {@link Container}
 * <li>k8s service configuration {@link Service}
 * <li>Che machine config {@link InternalMachineConfig}
 * <li>Fill in machine name attribute in related commands
 *
 * @throws InfrastructureException when any error occurs
 */
private void addSidecar(PodData pod, CheContainer container, ChePlugin chePlugin, KubernetesEnvironment k8sEnv, Collection<CommandImpl> sidecarRelatedCommands, Component pluginRelatedComponent, RuntimeIdentity runtimeIdentity) throws InfrastructureException {
    K8sContainerResolver k8sContainerResolver = toK8sContainerResolver(container, chePlugin.getEndpoints());
    List<ChePluginEndpoint> containerEndpoints = k8sContainerResolver.getEndpoints();
    Container k8sContainer = k8sContainerResolver.resolve();
    envVars.apply(k8sContainer, pluginRelatedComponent.getEnv());
    chePluginsVolumeApplier.applyVolumes(pod, k8sContainer, container.getVolumes(), k8sEnv);
    String machineName = k8sContainer.getName();
    Names.putMachineName(pod.getMetadata(), k8sContainer.getName(), machineName);
    pod.getSpec().getContainers().add(k8sContainer);
    MachineResolver machineResolver = new MachineResolverBuilder().setCheContainer(container).setContainer(k8sContainer).setContainerEndpoints(containerEndpoints).setDefaultSidecarMemoryLimitAttribute(defaultSidecarMemoryLimitBytes).setDefaultSidecarMemoryRequestAttribute(defaultSidecarMemoryRequestBytes).setDefaultSidecarCpuLimitAttribute(defaultSidecarCpuLimitCores).setDefaultSidecarCpuRequestAttribute(defaultSidecarCpuRequestCores).setProjectsRootPathEnvVar(projectsRootEnvVariableProvider.get(runtimeIdentity)).setComponent(pluginRelatedComponent).build();
    InternalMachineConfig machineConfig = machineResolver.resolve();
    machineConfig.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, TOOL_CONTAINER_SOURCE);
    machineConfig.getAttributes().put(PLUGIN_MACHINE_ATTRIBUTE, chePlugin.getId());
    k8sEnv.getMachines().put(machineName, machineConfig);
    sidecarRelatedCommands.forEach(c -> c.getAttributes().put(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE, machineName));
    container.getCommands().stream().map(c -> asCommand(machineName, c)).forEach(c -> k8sEnv.getCommands().add(c));
    SidecarServicesProvisioner sidecarServicesProvisioner = new SidecarServicesProvisioner(containerEndpoints, pod.getMetadata().getName());
    sidecarServicesProvisioner.provision(k8sEnv);
}
Also used : PLUGIN_MACHINE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.PLUGIN_MACHINE_ATTRIBUTE) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVars(org.eclipse.che.workspace.infrastructure.kubernetes.util.EnvVars) Singleton(javax.inject.Singleton) CONTAINER_SOURCE_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.CONTAINER_SOURCE_ATTRIBUTE) Function(java.util.function.Function) WORKING_DIRECTORY_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE) Inject(javax.inject.Inject) Names(org.eclipse.che.workspace.infrastructure.kubernetes.Names) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Map(java.util.Map) MACHINE_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE) Service(io.fabric8.kubernetes.api.model.Service) Named(javax.inject.Named) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Command(org.eclipse.che.api.workspace.server.wsplugins.model.Command) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ChePluginsApplier(org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier) TOOL_CONTAINER_SOURCE(org.eclipse.che.api.workspace.shared.Constants.TOOL_CONTAINER_SOURCE) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) Component(org.eclipse.che.api.core.model.workspace.devfile.Component) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Pod(io.fabric8.kubernetes.api.model.Pod) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Beta(com.google.common.annotations.Beta) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Warnings(org.eclipse.che.workspace.infrastructure.kubernetes.Warnings) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) ProjectsRootEnvVariableProvider(org.eclipse.che.api.workspace.server.spi.provision.env.ProjectsRootEnvVariableProvider) KubernetesSize(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSize) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)

Aggregations

KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)94 Test (org.testng.annotations.Test)68 Map (java.util.Map)30 HashMap (java.util.HashMap)28 Service (io.fabric8.kubernetes.api.model.Service)26 Container (io.fabric8.kubernetes.api.model.Container)24 Pod (io.fabric8.kubernetes.api.model.Pod)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)20 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)20 ArrayList (java.util.ArrayList)19 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)18 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)18 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)18 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)14 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)14 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)14 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)14