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

Various fixes after merging PR #16972 #17447

Merged
merged 5 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -533,6 +533,12 @@ che.workspace.devfile_registry_url=https://che-devfile-registry.prod-preview.ope
# - 'async': Experimental feature: Asynchronous storage is combination of Ephemeral
# and Persistent storage. Allows for faster I/O and keep your changes, will backup on stop
# and restore on start workspace.
# Will work only if:
# - che.infra.kubernetes.pvc.strategy='common'
# - che.limits.user.workspaces.run.count=1
# - che.infra.kubernetes.namespace.allow_user_defined=false
# - che.infra.kubernetes.namespace.default contains <username>
# in other cases remove 'async' from the list.
che.workspace.storage.available_types=persistent,ephemeral,async

# The configuration property that defines a default value for storage type that clients like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
*/
package org.eclipse.che.workspace.infrastructure.openshift;

import static com.google.common.base.Strings.isNullOrEmpty;
import static java.lang.Boolean.parseBoolean;
import static java.lang.String.format;
import static org.eclipse.che.api.workspace.shared.Constants.ASYNC_PERSIST_ATTRIBUTE;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.EphemeralWorkspaceUtility.isEphemeral;

import com.google.common.base.Strings;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -57,8 +57,10 @@ public class AsyncStorageModeValidator implements WorkspaceAttributeValidator {

private final String pvcStrategy;
private final boolean allowUserDefinedNamespaces;
private final String defaultNamespaceName;
private final int runtimesPerUser;
private final boolean isNamespaceStrategyNotValid;
private final boolean isPvcStrategyNotValid;
private final boolean singleRuntimeAllowed;

@Inject
public AsyncStorageModeValidator(
Expand All @@ -70,8 +72,12 @@ public AsyncStorageModeValidator(

this.pvcStrategy = pvcStrategy;
this.allowUserDefinedNamespaces = allowUserDefinedNamespaces;
this.defaultNamespaceName = defaultNamespaceName;
this.runtimesPerUser = runtimesPerUser;

this.isPvcStrategyNotValid = !COMMON_STRATEGY.equals(pvcStrategy);
this.singleRuntimeAllowed = runtimesPerUser == 1;
this.isNamespaceStrategyNotValid =
isNullOrEmpty(defaultNamespaceName) || !defaultNamespaceName.contains("<username>");
}

@Override
Expand Down Expand Up @@ -114,7 +120,7 @@ private void isEphemeralAttributeValidation(Map<String, String> attributes)
}

private void runtimesPerUserValidation() throws ValidationException {
if (runtimesPerUser > 1) {
if (!singleRuntimeAllowed) {
String message =
format(
"Workspace configuration not valid: Asynchronous storage available only if 'che.limits.user.workspaces.run.count' set to 1, but got %s",
Expand All @@ -125,8 +131,7 @@ private void runtimesPerUserValidation() throws ValidationException {
}

private void nameSpaceStrategyValidation() throws ValidationException {
if (Strings.isNullOrEmpty(defaultNamespaceName)
|| !defaultNamespaceName.contains("<username>")) {
if (isNamespaceStrategyNotValid) {
String message =
"Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy";
LOG.warn(message);
Expand All @@ -146,7 +151,7 @@ private void alowUserDefinedNamespaceValidation() throws ValidationException {
}

private void pvcStrategyValidation() throws ValidationException {
if (!COMMON_STRATEGY.equals(pvcStrategy)) {
if (isPvcStrategyNotValid) {
String message =
format(
"Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.workspace.infrastructure.kubernetes.Names;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil;
import org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder;
import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.slf4j.Logger;
Expand Down Expand Up @@ -369,15 +370,18 @@ private void createStorageServiceIfNotExist(
.withPort(SERVICE_PORT)
.withTargetPort(targetPort)
.build();

ServiceSpec spec = new ServiceSpec();
spec.setPorts(singletonList(port));
spec.setSelector(of("app", ASYNC_STORAGE));

Service service = new Service();
service.setApiVersion("v1");
service.setKind("Service");
service.setMetadata(meta);
service.setSpec(spec);
ServerServiceBuilder serviceBuilder = new ServerServiceBuilder();
Service service =
serviceBuilder
.withPorts(singletonList(port))
.withSelectorEntry("app", ASYNC_STORAGE)
.withName(ASYNC_STORAGE)
.build();

oc.services().inNamespace(namespace).create(service);
}
Expand Down