Skip to content

Commit

Permalink
Add internal and external API URL environment variables for workspaces (
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuznyetsov authored and hbhargav committed Dec 4, 2018
1 parent e10b0db commit 637f2d4
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.eclipse.che.api.workspace.server.spi.provision.ProjectsVolumeForWsAgentProvisioner;
import org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.EnvVarEnvironmentProvisioner;
import org.eclipse.che.api.workspace.server.spi.provision.env.EnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.JavaOptsEnvVariableProvider;
Expand Down Expand Up @@ -153,6 +155,8 @@ protected void configure() {
Multibinder<EnvVarProvider> envVarProviders =
Multibinder.newSetBinder(binder(), EnvVarProvider.class);
envVarProviders.addBinding().to(CheApiEnvVarProvider.class);
envVarProviders.addBinding().to(CheApiInternalEnvVarProvider.class);
envVarProviders.addBinding().to(CheApiExternalEnvVarProvider.class);
envVarProviders.addBinding().to(MachineTokenEnvVarProvider.class);
envVarProviders.addBinding().to(WorkspaceIdEnvVarProvider.class);

Expand Down
6 changes: 6 additions & 0 deletions dockerfiles/init/manifests/che.env
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
# The location of the API end point where dashboard and IDE clients will look for
# interacting with the Che server, which we also call the workspace master.
#CHE_API=${CHE_HOST_PROTOCOL}://${CHE_HOST}:${CHE_PORT}/api

# Che Server default websocket endpoint.
# Provides basic communication endpoint where clients can get/push statuses/output.
#CHE_WEBSOCKET_ENDPOINT=ws://${CHE_HOST}:${CHE_PORT}/api/websocket
Expand Down Expand Up @@ -258,12 +259,17 @@ CHE_SINGLE_PORT=false
# This variable is automatically overridden in single port mode.
#CHE_INFRA_DOCKER_URL__REWRITER=DEFAULT

# Time(in seconds) that limits the docker build process.
# The default value is 8 minutes, after which the build will be considered as failed.
# CHE_INFRA_DOCKER_BUILD__TIMEOUT__SEC=480

# HTTPS provider to read or generate HTTPS certificates. Currently possible options are:
# file (default)
# The "file" option expects the private key and chain in instance/config/traefik/che.key
# and instance/config/traefik/che.crt
#CHE_HTTPS_CERTIFICATE_PROVIDER=file


########################################################################################
##### #####
##### DOCKER #####
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.workspace.infrastructure.docker;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.commons.lang.Pair;

/**
* Provides env variable to docker machine with url of Che external API.
*
* @author Mykhailo Kuznietsov
*/
@Singleton
public class DockerCheApiExternalEnvVarProvider implements CheApiExternalEnvVarProvider {

private final Pair<String, String> apiEnvVar;

@Inject
public DockerCheApiExternalEnvVarProvider(@Named("che.api") String apiEndpoint) {
apiEnvVar = Pair.of(CHE_API_EXTERNAL_VARIABLE, apiEndpoint);
}

@Override
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) {
return apiEnvVar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.commons.lang.Pair;

/**
* Provides env variable to docker machine with url of Che API.
*
* @author Alexander Garagatyi
* @author Mykhailo Kuznietsov
*/
@Singleton
public class DockerCheApiEnvVarProvider implements CheApiEnvVarProvider {
public class DockerCheApiInternalEnvVarProvider implements CheApiInternalEnvVarProvider {

private Pair<String, String> apiEnvVar;
private static final String CHE_API_VARIABLE = "CHE_API";

private final Pair<String, String> apiEnvVar;

@Inject
public DockerCheApiEnvVarProvider(
public DockerCheApiInternalEnvVarProvider(
@Named("che.infra.docker.master_api_endpoint") String apiEndpoint) {
String apiEndpointEnvVar = System.getenv(API_ENDPOINT_URL_VARIABLE);
String apiEndpointEnvVar = System.getenv(CHE_API_VARIABLE);
if (Strings.isNullOrEmpty(apiEndpoint) && !Strings.isNullOrEmpty(apiEndpointEnvVar)) {
apiEndpoint = apiEndpointEnvVar;
}
apiEnvVar = Pair.of(API_ENDPOINT_URL_VARIABLE, apiEndpoint);
apiEnvVar = Pair.of(CHE_API_INTERNAL_VARIABLE, apiEndpoint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import com.google.inject.multibindings.Multibinder;
import org.eclipse.che.api.workspace.server.URLRewriter;
import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.infrastructure.docker.client.DockerRegistryDynamicAuthResolver;
import org.eclipse.che.infrastructure.docker.client.NoOpDockerRegistryDynamicAuthResolverImpl;
import org.eclipse.che.workspace.infrastructure.docker.bootstrap.DockerBootstrapperFactory;
Expand Down Expand Up @@ -60,7 +61,8 @@ protected void configure() {
install(new DockerEnvironmentConvertersModule());
install(new ContainerSystemSettingsProvisioningModule());

bind(CheApiEnvVarProvider.class).to(DockerCheApiEnvVarProvider.class);
bind(CheApiInternalEnvVarProvider.class).to(DockerCheApiInternalEnvVarProvider.class);
bind(CheApiExternalEnvVarProvider.class).to(DockerCheApiExternalEnvVarProvider.class);

bind(RuntimeInfrastructure.class).to(DockerRuntimeInfrastructure.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import java.util.Map;
import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.EnvVarProvider;
import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.DockerImageEnvironment;
import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.DockerImageEnvironmentFactory;
Expand All @@ -41,7 +42,8 @@
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspacePVCCleaner;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumeStrategyProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiExternalEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiInternalEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.env.LogsRootEnvVariableProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.server.ServersConverter;
import org.eclipse.che.workspace.infrastructure.kubernetes.server.DefaultHostIngressExternalServerExposer;
Expand Down Expand Up @@ -70,7 +72,8 @@ protected void configure() {
bind(WorkspacePVCCleaner.class).asEagerSingleton();
bind(RemoveNamespaceOnWorkspaceRemove.class).asEagerSingleton();

bind(CheApiEnvVarProvider.class).to(KubernetesCheApiEnvVarProvider.class);
bind(CheApiInternalEnvVarProvider.class).to(KubernetesCheApiInternalEnvVarProvider.class);
bind(CheApiExternalEnvVarProvider.class).to(KubernetesCheApiExternalEnvVarProvider.class);

MapBinder<String, WorkspaceVolumesStrategy> volumesStrategies =
MapBinder.newMapBinder(binder(), String.class, WorkspaceVolumesStrategy.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
import javax.inject.Named;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.commons.lang.Pair;

/**
* Provides env variable to Kubernetes machine with url of Che API.
*
* @author Sergii Leshchenko
* @author Mykhailo Kuznietsov
*/
public class KubernetesCheApiEnvVarProvider implements CheApiEnvVarProvider {
public class KubernetesCheApiExternalEnvVarProvider implements CheApiExternalEnvVarProvider {

private final String cheServerEndpoint;

@Inject
public KubernetesCheApiEnvVarProvider(@Named("che.api") String cheServerEndpoint) {
public KubernetesCheApiExternalEnvVarProvider(@Named("che.api") String cheServerEndpoint) {
this.cheServerEndpoint = cheServerEndpoint;
}

@Override
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException {
return Pair.of("CHE_API", cheServerEndpoint);
return Pair.of(CHE_API_EXTERNAL_VARIABLE, cheServerEndpoint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.provision;

import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.commons.lang.Pair;

/**
* Provides env variable to Kubernetes machine with url of Che API.
*
* @author Mykhailo Kuznietsov
*/
public class KubernetesCheApiInternalEnvVarProvider implements CheApiInternalEnvVarProvider {

private final String cheServerEndpoint;

@Inject
public KubernetesCheApiInternalEnvVarProvider(@Named("che.api") String cheServerEndpoint) {
this.cheServerEndpoint = cheServerEndpoint;
}

@Override
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException {
return Pair.of(CHE_API_INTERNAL_VARIABLE, cheServerEndpoint);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import com.google.inject.multibindings.Multibinder;
import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiExternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.CheApiInternalEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.EnvVarProvider;
import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.DockerImageEnvironment;
import org.eclipse.che.workspace.infrastructure.docker.environment.dockerimage.DockerImageEnvironmentFactory;
Expand All @@ -35,7 +36,8 @@
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspacePVCCleaner;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumeStrategyProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiExternalEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesCheApiInternalEnvVarProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.env.LogsRootEnvVariableProvider;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.server.ServersConverter;
import org.eclipse.che.workspace.infrastructure.kubernetes.server.ExternalServerExposerStrategy;
Expand Down Expand Up @@ -66,7 +68,8 @@ protected void configure() {
bind(WorkspacePVCCleaner.class).asEagerSingleton();
bind(RemoveProjectOnWorkspaceRemove.class).asEagerSingleton();

bind(CheApiEnvVarProvider.class).to(KubernetesCheApiEnvVarProvider.class);
bind(CheApiInternalEnvVarProvider.class).to(KubernetesCheApiInternalEnvVarProvider.class);
bind(CheApiExternalEnvVarProvider.class).to(KubernetesCheApiExternalEnvVarProvider.class);

MapBinder<String, WorkspaceVolumesStrategy> volumesStrategies =
MapBinder.newMapBinder(binder(), String.class, WorkspaceVolumesStrategy.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,40 @@
*/
package org.eclipse.che.api.workspace.server.spi.provision.env;

import javax.inject.Inject;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.commons.lang.Pair;

/** @author Sergii Leshchenko */
public interface CheApiEnvVarProvider extends EnvVarProvider {
/**
* CHE_API endpoint var provided. For all currently supported infrastructures, it reuses {@link
* CheApiInternalEnvVarProvider} to provide the value.
*
* @deprecated this class shall soon be removed, as this variable is provided only for backward
* compatibility
* @author Sergii Leshchenko
* @author Mykhailo Kuznietsov
*/
@Deprecated
public class CheApiEnvVarProvider implements EnvVarProvider {

/** Che API url */
public static final String CHE_API_VARIABLE = "CHE_API";

private final CheApiInternalEnvVarProvider cheApiInternalEnvVarProvider;

/** Env variable for machine that contains url of Che API */
String API_ENDPOINT_URL_VARIABLE = "CHE_API";
@Inject
public CheApiEnvVarProvider(CheApiInternalEnvVarProvider cheApiInternalEnvVarProvider) {
this.cheApiInternalEnvVarProvider = cheApiInternalEnvVarProvider;
}

/**
* Returns Che API environment variable which should be injected into machines.
*
* @param runtimeIdentity which may be needed to evaluate environment variable value
*/
@Override
Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException;
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException {
return Pair.of(CHE_API_VARIABLE, cheApiInternalEnvVarProvider.get(runtimeIdentity).second);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.workspace.server.spi.provision.env;

import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.commons.lang.Pair;

/** @author Mykhailo Kuznietsov */
public interface CheApiExternalEnvVarProvider extends EnvVarProvider {

/** Env variable for machine that contains url of Che API */
String CHE_API_EXTERNAL_VARIABLE = "CHE_API_EXTERNAL";

/**
* Returns Che API environment variable which should be injected into machines. External API URL
* is meant to be used by external clients like browsers.
*
* @param runtimeIdentity which may be needed to evaluate environment variable value
*/
@Override
Pair<String, String> get(RuntimeIdentity runtimeIdentity) throws InfrastructureException;
}
Loading

0 comments on commit 637f2d4

Please sign in to comment.