-
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
30 changed files
with
1,846 additions
and
152 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
70 changes: 70 additions & 0 deletions
70
...org/eclipse/che/workspace/infrastructure/kubernetes/CheServerKubernetesClientFactory.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,70 @@ | ||
/* | ||
* 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; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import okhttp3.EventListener; | ||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException; | ||
import org.eclipse.che.commons.annotation.Nullable; | ||
|
||
/** | ||
* This {@link KubernetesClientFactory} is used to access Che installation namespace. It always | ||
* provides client with default {@link Config}. | ||
*/ | ||
@Singleton | ||
public class CheServerKubernetesClientFactory extends KubernetesClientFactory { | ||
|
||
@Inject | ||
public CheServerKubernetesClientFactory( | ||
@Nullable @Named("che.infra.kubernetes.master_url") String masterUrl, | ||
@Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts, | ||
@Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests, | ||
@Named("che.infra.kubernetes.client.http.async_requests.max_per_host") | ||
int maxConcurrentRequestsPerHost, | ||
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections, | ||
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min") | ||
int connectionPoolKeepAlive, | ||
EventListener eventListener) { | ||
super( | ||
masterUrl, | ||
doTrustCerts, | ||
maxConcurrentRequests, | ||
maxConcurrentRequestsPerHost, | ||
maxIdleConnections, | ||
connectionPoolKeepAlive, | ||
eventListener); | ||
} | ||
|
||
/** @param workspaceId ignored */ | ||
@Override | ||
public KubernetesClient create(String workspaceId) throws InfrastructureException { | ||
return create(); | ||
} | ||
|
||
/** | ||
* creates an instance of {@link KubernetesClient} that is meant to be used on Che installation | ||
* namespace | ||
*/ | ||
@Override | ||
public KubernetesClient create() throws InfrastructureException { | ||
return super.create(); | ||
} | ||
|
||
@Override | ||
protected Config buildConfig(Config config, String workspaceId) { | ||
return config; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
.../eclipse/che/workspace/infrastructure/kubernetes/environment/CheInstallationLocation.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,49 @@ | ||
/* | ||
* 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.environment; | ||
|
||
import com.google.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException; | ||
|
||
/** | ||
* This class checks the KUBERNETES_NAMESPACE and POD_NAMESPACE environment variables to determine | ||
* what namespace Che is installed in. Users should use this class to retrieve the installation | ||
* namespace name. | ||
* | ||
* @author Tom George | ||
*/ | ||
@Singleton | ||
public class CheInstallationLocation { | ||
@Inject(optional = true) | ||
@Named("env.KUBERNETES_NAMESPACE") | ||
String kubernetesNamespace; | ||
|
||
@Inject(optional = true) | ||
@Named("env.POD_NAMESPACE") | ||
String podNamespace; | ||
|
||
/** | ||
* @return The name of the namespace where Che is installed or null if both {@code | ||
* KUBERNETES_NAMESPACE} and {@code POD_NAMESPACE} environment variables are not set | ||
* @throws InfrastructureException when both {@code KUBERNETES_NAMESPACE} and {@code | ||
* POD_NAMESPACE} are null | ||
*/ | ||
public String getInstallationLocationNamespace() throws InfrastructureException { | ||
if (kubernetesNamespace == null && podNamespace == null) { | ||
throw new InfrastructureException( | ||
"Neither KUBERNETES_NAMESPACE nor POD_NAMESPACE is defined. Unable to determine Che installation location"); | ||
} | ||
return kubernetesNamespace == null ? podNamespace : kubernetesNamespace; | ||
} | ||
} |
Oops, something went wrong.