Skip to content

Commit

Permalink
Various fixes after meging PR #16972
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Parfonov <[email protected]>
  • Loading branch information
vparfonov committed Jul 20, 2020
1 parent 593f915 commit aa7cacf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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 runtimesPerUserLimited;

@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.runtimesPerUserLimited = 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 (runtimesPerUserLimited) {
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

0 comments on commit aa7cacf

Please sign in to comment.