Search in sources :

Example 1 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindServiceForPreviewurl.

@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
    List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
    Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
    Mockito.when(mockProject.services()).thenReturn(mockServices);
    Mockito.when(mockServices.get()).thenReturn(Collections.emptyList());
    previewUrlCommandProvisioner.provision(env, mockProject);
    assertTrue(commands.containsAll(env.getCommands()));
    assertTrue(env.getCommands().containsAll(commands));
    assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost.

@Test
public void shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost() {
    // given
    RouteServerExposer osExternalServerExposer = new RouteServerExposer(LABELS, "open.che.org");
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
    Map<String, ServerConfig> servers = new HashMap<>();
    servers.put("server", new ServerConfigImpl());
    // when
    osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
    // then
    assertEquals(1, osEnv.getRoutes().size());
    Route route = osEnv.getRoutes().values().iterator().next();
    assertNotNull(route);
    assertEquals(route.getSpec().getTo().getName(), "service123");
    assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
    assertTrue(route.getSpec().getHost().endsWith(".open.che.org"));
    assertTrue(route.getSpec().getHost().startsWith("route"));
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 3 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlExposerTest method shouldProvisionRouteWhenNotFound.

@Test
public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    final String SERVICE_NAME = "servicename";
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName(SERVICE_NAME);
    service.setMetadata(serviceMeta);
    ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
    service.setSpec(serviceSpec);
    Map<String, Service> services = new HashMap<>();
    services.put(SERVICE_NAME, service);
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(new HashMap<>()).build();
    previewUrlEndpointsProvisioner.expose(env);
    assertEquals(env.getRoutes().size(), 1);
    Route provisionedRoute = env.getRoutes().values().iterator().next();
    assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME);
    assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 4 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlExposerTest method shouldDoNothingWhenNoCommandWithPreviewUrlDefined.

@Test
public void shouldDoNothingWhenNoCommandWithPreviewUrlDefined() throws InternalInfrastructureException {
    CommandImpl command = new CommandImpl("a", "a", "a");
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).build();
    previewUrlEndpointsProvisioner.expose(env);
    assertEquals(env.getCommands().get(0), command);
    assertTrue(env.getServices().isEmpty());
    assertTrue(env.getRoutes().isEmpty());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) Test(org.testng.annotations.Test)

Example 5 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftInfraModule method configure.

@Override
protected void configure() {
    Multibinder<WorkspaceAttributeValidator> workspaceAttributeValidators = Multibinder.newSetBinder(binder(), WorkspaceAttributeValidator.class);
    workspaceAttributeValidators.addBinding().to(K8sInfraNamespaceWsAttributeValidator.class);
    workspaceAttributeValidators.addBinding().to(AsyncStorageModeValidator.class);
    Multibinder<NamespaceConfigurator> namespaceConfigurators = Multibinder.newSetBinder(binder(), NamespaceConfigurator.class);
    namespaceConfigurators.addBinding().to(UserProfileConfigurator.class);
    namespaceConfigurators.addBinding().to(UserPreferencesConfigurator.class);
    namespaceConfigurators.addBinding().to(CredentialsSecretConfigurator.class);
    namespaceConfigurators.addBinding().to(PreferencesConfigMapConfigurator.class);
    namespaceConfigurators.addBinding().to(OpenShiftWorkspaceServiceAccountConfigurator.class);
    namespaceConfigurators.addBinding().to(OpenShiftStopWorkspaceRoleConfigurator.class);
    namespaceConfigurators.addBinding().to(SshKeysConfigurator.class);
    bind(KubernetesNamespaceService.class);
    MapBinder<String, InternalEnvironmentFactory> factories = MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
    factories.addBinding(OpenShiftEnvironment.TYPE).to(OpenShiftEnvironmentFactory.class);
    factories.addBinding(KubernetesEnvironment.TYPE).to(KubernetesEnvironmentFactory.class);
    factories.addBinding(Constants.NO_ENVIRONMENT_RECIPE_TYPE).to(NoEnvironmentFactory.class);
    bind(InconsistentRuntimesDetector.class).asEagerSingleton();
    bind(RuntimeInfrastructure.class).to(OpenShiftInfrastructure.class);
    bind(KubernetesNamespaceFactory.class).to(OpenShiftProjectFactory.class);
    bind(KubernetesClientFactory.class).to(OpenShiftClientFactory.class);
    bind(CheServerOpenshiftClientFactory.class);
    install(new FactoryModuleBuilder().build(OpenShiftRuntimeContextFactory.class));
    install(new FactoryModuleBuilder().build(OpenShiftRuntimeFactory.class));
    install(new FactoryModuleBuilder().build(StartSynchronizerFactory.class));
    bind(WorkspacePVCCleaner.class).asEagerSingleton();
    bind(RemoveProjectOnWorkspaceRemove.class).asEagerSingleton();
    bind(TrustedCAProvisioner.class).to(OpenshiftTrustedCAProvisioner.class);
    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);
    MapBinder<WorkspaceExposureType, ExternalServerExposer<OpenShiftEnvironment>> exposureStrategies = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
    }, new TypeLiteral<>() {
    });
    exposureStrategies.addBinding(WorkspaceExposureType.NATIVE).to(RouteServerExposer.class);
    exposureStrategies.addBinding(WorkspaceExposureType.GATEWAY).to(new TypeLiteral<GatewayServerExposer<OpenShiftEnvironment>>() {
    });
    bind(new TypeLiteral<ExternalServerExposer<OpenShiftEnvironment>>() {
    }).annotatedWith(com.google.inject.name.Names.named("multihost-exposer")).to(RouteServerExposer.class);
    bind(new TypeLiteral<ExternalServerExposerProvider<OpenShiftEnvironment>>() {
    }).to(OpenShiftExternalServerExposerProvider.class);
    bind(ServersConverter.class).to(new TypeLiteral<ServersConverter<OpenShiftEnvironment>>() {
    });
    bind(PreviewUrlExposer.class).to(new TypeLiteral<OpenShiftPreviewUrlExposer>() {
    });
    bind(PreviewUrlCommandProvisioner.class).to(new TypeLiteral<OpenShiftPreviewUrlCommandProvisioner>() {
    });
    Multibinder<EnvVarProvider> envVarProviders = Multibinder.newSetBinder(binder(), EnvVarProvider.class);
    envVarProviders.addBinding().to(LogsRootEnvVariableProvider.class);
    install(new JpaKubernetesRuntimeCacheModule());
    Multibinder.newSetBinder(binder(), ServiceTermination.class).addBinding().to(KubernetesClientTermination.class);
    MapBinder<String, ChePluginsApplier> pluginsAppliers = MapBinder.newMapBinder(binder(), String.class, ChePluginsApplier.class);
    pluginsAppliers.addBinding(OpenShiftEnvironment.TYPE).to(KubernetesPluginsToolingApplier.class);
    bind(SecureServerExposerFactoryProvider.class).to(new TypeLiteral<SecureServerExposerFactoryProvider<OpenShiftEnvironment>>() {
    });
    bind(BrokerService.class);
    bind(new TypeLiteral<BrokerEnvironmentFactory<OpenShiftEnvironment>>() {
    }).to(OpenshiftBrokerEnvironmentFactory.class);
    bind(PluginBrokerManager.class).to(new TypeLiteral<PluginBrokerManager<OpenShiftEnvironment>>() {
    });
    bind(SidecarToolingProvisioner.class).to(new TypeLiteral<SidecarToolingProvisioner<OpenShiftEnvironment>>() {
    });
    MapBinder<WorkspaceExposureType, TlsProvisioner<OpenShiftEnvironment>> tlsProvisioners = MapBinder.newMapBinder(binder(), new TypeLiteral<WorkspaceExposureType>() {
    }, new TypeLiteral<TlsProvisioner<OpenShiftEnvironment>>() {
    });
    tlsProvisioners.addBinding(WorkspaceExposureType.GATEWAY).to(new TypeLiteral<GatewayTlsProvisioner<OpenShiftEnvironment>>() {
    });
    tlsProvisioners.addBinding(WorkspaceExposureType.NATIVE).to(RouteTlsProvisioner.class);
    bind(new TypeLiteral<KubernetesEnvironmentProvisioner<OpenShiftEnvironment>>() {
    }).to(OpenShiftEnvironmentProvisioner.class);
    DevfileBindings.onComponentIntegrityValidatorBinder(binder(), binder -> {
        binder.addBinding(KUBERNETES_COMPONENT_TYPE).to(KubernetesComponentValidator.class);
        binder.addBinding(OPENSHIFT_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);
        binder.addBinding(OPENSHIFT_COMPONENT_TYPE).to(OpenshiftComponentToWorkspaceApplier.class);
    });
    KubernetesDevfileBindings.addKubernetesBasedEnvironmentTypeBindings(binder(), KubernetesEnvironment.TYPE, OpenShiftEnvironment.TYPE);
    KubernetesDevfileBindings.addKubernetesBasedComponentTypeBindings(binder(), KUBERNETES_COMPONENT_TYPE, OPENSHIFT_COMPONENT_TYPE);
    KubernetesDevfileBindings.addAllowedEnvironmentTypeUpgradeBindings(binder(), OpenShiftEnvironment.TYPE, KubernetesEnvironment.TYPE);
    MapBinder<String, ExternalServiceExposureStrategy> ingressStrategies = MapBinder.newMapBinder(binder(), String.class, ExternalServiceExposureStrategy.class);
    ingressStrategies.addBinding(MULTI_HOST_STRATEGY).to(OpenShiftServerExposureStrategy.class);
    ingressStrategies.addBinding(SINGLE_HOST_STRATEGY).to(SingleHostExternalServiceExposureStrategy.class);
    bind(ExternalServiceExposureStrategy.class).toProvider(ServiceExposureStrategyProvider.class);
    bind(CookiePathStrategy.class).to(OpenShiftCookiePathStrategy.class);
    bind(NonTlsDistributedClusterModeNotifier.class);
    bind(AsyncStorageProvisioner.class);
    bind(AsyncStoragePodInterceptor.class);
    bind(AsyncStoragePodWatcher.class);
}
Also used : RemoveProjectOnWorkspaceRemove(org.eclipse.che.workspace.infrastructure.openshift.project.RemoveProjectOnWorkspaceRemove) OpenShiftPreviewUrlExposer(org.eclipse.che.workspace.infrastructure.openshift.server.OpenShiftPreviewUrlExposer) 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) OpenShiftPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.openshift.provision.OpenShiftPreviewUrlCommandProvisioner) PreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.PreviewUrlCommandProvisioner) StartSynchronizerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.StartSynchronizerFactory) SingleHostExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy) 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) InconsistentRuntimesDetector(org.eclipse.che.workspace.infrastructure.kubernetes.InconsistentRuntimesDetector) 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) OpenShiftPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.openshift.provision.OpenShiftPreviewUrlCommandProvisioner) 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) RuntimeInfrastructure(org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure) CookiePathStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.CookiePathStrategy) OpenShiftCookiePathStrategy(org.eclipse.che.workspace.infrastructure.openshift.server.OpenShiftCookiePathStrategy) NamespaceConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator) TlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TlsProvisioner) GatewayTlsProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.GatewayTlsProvisioner) RouteTlsProvisioner(org.eclipse.che.workspace.infrastructure.openshift.provision.RouteTlsProvisioner) KubernetesNamespaceFactory(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) WorkspaceExposureType(org.eclipse.che.workspace.infrastructure.kubernetes.server.WorkspaceExposureType) OpenShiftPreviewUrlExposer(org.eclipse.che.workspace.infrastructure.openshift.server.OpenShiftPreviewUrlExposer) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) 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) 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) KubernetesClientFactory(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory) OpenshiftTrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.openshift.provision.OpenshiftTrustedCAProvisioner) TrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TrustedCAProvisioner)

Aggregations

OpenShiftEnvironment (org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment)28 Test (org.testng.annotations.Test)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)16 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)14 Route (io.fabric8.openshift.api.model.Route)14 Service (io.fabric8.kubernetes.api.model.Service)12 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)12 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)10 HashMap (java.util.HashMap)10 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)8 ArrayList (java.util.ArrayList)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)6 TypeLiteral (com.google.inject.TypeLiteral)4 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)4 RoutePort (io.fabric8.openshift.api.model.RoutePort)4 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)4 RouteTargetReference (io.fabric8.openshift.api.model.RouteTargetReference)4 ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)4 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2