-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Michal Vala <mvala@redhat.com>
- Loading branch information
Showing
26 changed files
with
482 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
.../workspace/infrastructure/kubernetes/server/external/CombinedSingleHostServerExposer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.server.external; | ||
|
||
import static java.lang.Boolean.FALSE; | ||
import static org.eclipse.che.api.core.model.workspace.config.ServerConfig.DEVFILE_ENDPOINT; | ||
|
||
import io.fabric8.kubernetes.api.model.ServicePort; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.eclipse.che.api.core.model.workspace.config.ServerConfig; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; | ||
|
||
/** | ||
* This {@link ExternalServerExposer} is used in single-host mode when we need to expose some | ||
* servers on subdomain, instead of subpaths. | ||
* | ||
* <p>It aggregates 2 {@link ExternalServerExposer}s, using one to expose servers on subdomand, and | ||
* 2nd to expose servers on subpaths. It determines which to use for individual server based on some | ||
* attribute in {@link ServerConfig#getAttributes()} (see implementation {@link | ||
* CombinedSingleHostServerExposer#expose(KubernetesEnvironment, String, String, String, | ||
* ServicePort, Map)} for the details). | ||
* | ||
* @param <T> environment type | ||
*/ | ||
public class CombinedSingleHostServerExposer<T extends KubernetesEnvironment> | ||
implements ExternalServerExposer<T> { | ||
|
||
private final ExternalServerExposer<T> subdomainServerExposer; | ||
private final ExternalServerExposer<T> subpathServerExposer; | ||
|
||
public CombinedSingleHostServerExposer( | ||
ExternalServerExposer<T> subdomainServerExposer, | ||
ExternalServerExposer<T> subpathServerExposer) { | ||
this.subdomainServerExposer = subdomainServerExposer; | ||
this.subpathServerExposer = subpathServerExposer; | ||
} | ||
|
||
/** | ||
* Exposes given 'externalServers' to either subdomain or subpath, using 2 different {@link | ||
* ExternalServerExposer}s. Which one to use for individual server is determined with {@link | ||
* ServerConfig#DEVFILE_ENDPOINT} attribute. | ||
* | ||
* @param k8sEnv environment | ||
* @param machineName machine containing servers | ||
* @param serviceName service associated with machine, mapping all machine server ports | ||
* @param serverId non-null for a unique server, null for a compound set of servers that should be | ||
* exposed together. | ||
* @param servicePort specific service port to be exposed externally | ||
* @param externalServers server configs of servers to be exposed externally | ||
*/ | ||
@Override | ||
public void expose( | ||
T k8sEnv, | ||
String machineName, | ||
String serviceName, | ||
String serverId, | ||
ServicePort servicePort, | ||
Map<String, ServerConfig> externalServers) { | ||
|
||
if (serverId == null) { | ||
// this is the ID for non-unique servers | ||
serverId = servicePort.getName(); | ||
} | ||
|
||
Map<String, ServerConfig> subpathServers = new HashMap<>(); | ||
Map<String, ServerConfig> subdomainServers = new HashMap<>(); | ||
|
||
for (String esKey : externalServers.keySet()) { | ||
ServerConfig serverConfig = externalServers.get(esKey); | ||
if (Boolean.parseBoolean( | ||
serverConfig.getAttributes().getOrDefault(DEVFILE_ENDPOINT, FALSE.toString()))) { | ||
subdomainServers.put(esKey, serverConfig); | ||
} else { | ||
subpathServers.put(esKey, serverConfig); | ||
} | ||
} | ||
|
||
if (!subpathServers.isEmpty()) { | ||
subpathServerExposer.expose( | ||
k8sEnv, machineName, serviceName, serverId, servicePort, subpathServers); | ||
} | ||
|
||
if (!subdomainServers.isEmpty()) { | ||
subdomainServerExposer.expose( | ||
k8sEnv, machineName, serviceName, serverId, servicePort, subdomainServers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ce/infrastructure/kubernetes/server/external/KubernetesExternalServerExposerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.server.external; | ||
|
||
import static org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY; | ||
import static org.eclipse.che.workspace.infrastructure.kubernetes.server.external.SingleHostExternalServiceExposureStrategy.SINGLE_HOST_STRATEGY; | ||
|
||
import java.util.Map; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.server.AbstractExposureStrategyAwareProvider; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.server.WorkspaceExposureType; | ||
|
||
/** | ||
* Provides {@link ExternalServerExposer} based on `che.infra.kubernetes.server_strategy` and | ||
* `che.infra.kubernetes.singlehost.workspace.exposure` properties. | ||
* | ||
* <p>Based on server strategy, it can create a {@link CombinedSingleHostServerExposer} with | ||
* Kubernetes specific {@link IngressServerExposer} for exposing servers on subdomains. | ||
* | ||
* @param <T> type of environment | ||
*/ | ||
@Singleton | ||
public class KubernetesExternalServerExposerProvider<T extends KubernetesEnvironment> | ||
extends AbstractExposureStrategyAwareProvider<ExternalServerExposer<T>> | ||
implements ExternalServerExposerProvider<T> { | ||
|
||
private final ExternalServerExposer<T> combinedInstance; | ||
|
||
@Inject | ||
public KubernetesExternalServerExposerProvider( | ||
@Named("che.infra.kubernetes.server_strategy") String exposureStrategy, | ||
@Named("che.infra.kubernetes.singlehost.workspace.exposure") String exposureType, | ||
@Named("che.infra.kubernetes.singlehost.workspace.devfile_endpoint_exposure") | ||
String devfileEndpointsExposure, | ||
@Named("multihost-exposer") ExternalServerExposer<T> multihostExposer, | ||
Map<WorkspaceExposureType, ExternalServerExposer<T>> exposers) { | ||
super( | ||
exposureStrategy, | ||
exposureType, | ||
exposers, | ||
"Could not find an external server exposer implementation for the exposure type '%s'."); | ||
|
||
if (SINGLE_HOST_STRATEGY.equals(exposureStrategy) | ||
&& MULTI_HOST_STRATEGY.equals(devfileEndpointsExposure)) { | ||
this.combinedInstance = new CombinedSingleHostServerExposer<>(multihostExposer, instance); | ||
} else { | ||
this.combinedInstance = null; | ||
} | ||
} | ||
|
||
@Override | ||
public ExternalServerExposer<T> get() { | ||
return combinedInstance != null ? combinedInstance : instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...he/workspace/infrastructure/kubernetes/server/external/MultihostIngressServerExposer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.server.external; | ||
|
||
import io.fabric8.kubernetes.api.model.extensions.Ingress; | ||
import java.util.Map; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.commons.annotation.Nullable; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; | ||
|
||
/** | ||
* Uses Kubernetes {@link Ingress}es to expose the services using subdomains a.k.a. multi-host. | ||
* | ||
* @see ExternalServerExposer | ||
*/ | ||
@Singleton | ||
public class MultihostIngressServerExposer<T extends KubernetesEnvironment> | ||
extends IngressServerExposer<T> implements ExternalServerExposer<T> { | ||
@Inject | ||
public MultihostIngressServerExposer( | ||
MultiHostExternalServiceExposureStrategy serviceExposureStrategy, | ||
@Named("infra.kubernetes.ingress.annotations") Map<String, String> annotations, | ||
@Nullable @Named("che.infra.kubernetes.ingress.labels") String labelsProperty, | ||
@Nullable @Named("che.infra.kubernetes.ingress.path_transform") String pathTransformFmt) { | ||
super(serviceExposureStrategy, annotations, labelsProperty, pathTransformFmt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.