Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal and external API URL environment variables for workspaces #9475

Merged
merged 22 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
61e2780
Provide internal and external api url into workspaces
mkuznyetsov Apr 11, 2018
3ff7e90
Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 13, 2018
4e07ca8
fixup! Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 18, 2018
5b2695c
fixup! fixup! Merge branch 'master' of github.com:eclipse/che into ch…
mkuznyetsov Apr 18, 2018
f1c129c
fixup! fixup! fixup! Merge branch 'master' of github.com:eclipse/che …
mkuznyetsov Apr 18, 2018
25133b1
fixup! fixup! fixup! fixup! Merge branch 'master' of github.com:eclip…
mkuznyetsov Apr 18, 2018
f42a5a8
fixup! fixup! fixup! fixup! fixup! Merge branch 'master' of github.co…
mkuznyetsov Apr 18, 2018
308c5a5
fixup! fixup! fixup! fixup! fixup! fixup! Merge branch 'master' of gi…
mkuznyetsov Apr 18, 2018
b8fa831
Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 18, 2018
8ddeb71
test
Apr 18, 2018
d75bc47
Update ocp.sh
Apr 18, 2018
9ee2ad7
Tets envs
Apr 18, 2018
aea61c2
Remove testing echo
Apr 19, 2018
58fffc9
Remove odd classes
mkuznyetsov Apr 24, 2018
ab94315
fixup! Remove odd classes
mkuznyetsov Apr 24, 2018
d64d787
fixup! fixup! Remove odd classes
mkuznyetsov Apr 24, 2018
fbffe2a
fixup! fixup! fixup! Remove odd classes
mkuznyetsov Apr 24, 2018
e9574ec
Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 24, 2018
5984ec0
fixup! Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 25, 2018
773de1e
fixup! fixup! Merge branch 'master' of github.com:eclipse/che into ch…
mkuznyetsov Apr 25, 2018
95da304
Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 26, 2018
08d85d9
Merge branch 'master' of github.com:eclipse/che into che-9323
mkuznyetsov Apr 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 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=http://${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
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