diff --git a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties index 9eeb5f5624b..b55a119c8c8 100644 --- a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties +++ b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties @@ -289,24 +289,6 @@ che.infra.kubernetes.singlehost.gateway.configmap_labels=app=che,component=che-g # Used to generate domain for a server in a workspace in case property `che.infra.kubernetes.server_strategy` is set to `multi-host` che.infra.kubernetes.ingress.domain= -# DEPRECATED - Do not change the value of this property otherwise the existing workspaces will loose data. Do not -# set it on new installations. -# -# Defines Kubernetes namespace in which all workspaces will be created. -# If not set, every workspace will be created in a new namespace, where namespace = workspace id -# It's possible to use `` and `` placeholders (for example: `che-workspace-`). -# In that case, new namespace will be created for each user. Service account with permission -# to create new namespace must be used. -# -# Ignored for OpenShift infra. Use `che.infra.openshift.project` instead -# -# If the namespace pointed to by this property exists, it will be used for all workspaces. If it does not exist, -# the namespace specified by `che.infra.kubernetes.namespace.default` will be created and used. -# This parameter is subject to removal in future releases. -# Legacy workspaces located in this namespace may become unreachable in future releases. -# See the documentation about possible next steps. -che.infra.kubernetes.namespace= - # Indicates whether {prod-short} server is allowed to create {orch-namespace} for user # workspaces, or they're intended to be created manually by cluster administrator. # This property is also used by the OpenShift infra. @@ -315,9 +297,8 @@ che.infra.kubernetes.namespace.creation_allowed=true # Defines Kubernetes default namespace in which user's workspaces are created # if user does not override it. # It's possible to use `` and `` placeholders (for example: `che-workspace-`). -# In that case, new namespace will be created for each user (or workspace). +# In that case, new namespace will be created for each user. # Used by OpenShift infra as well to specify a Project. -# The `` placeholder is deprecated and is subject to removal in future releases. # The `` or `` placeholder is mandatory. che.infra.kubernetes.namespace.default=-che @@ -337,10 +318,6 @@ che.infra.kubernetes.namespace.labels=app.kubernetes.io/part-of=che.eclipse.org, # It's possible to use `` placeholder to specify the {orch-namespace} to concrete user. che.infra.kubernetes.namespace.annotations=che.eclipse.org/username= -# Defines if a user is able to specify {orch-namespace} different from the default. -# It's NOT RECOMMENDED to configured true without OAuth configured. This property is also used by the OpenShift infra. -che.infra.kubernetes.namespace.allow_user_defined=false - # Defines Kubernetes Service Account name which should be specified to be bound to all workspaces Pods. # the {prod-short} Operator that Kubernetes Infrastructure will not create the service account and it should exist. # OpenShift infrastructure will check if project is predefined(if `che.infra.openshift.project` is not empty): @@ -561,25 +538,6 @@ che.infra.kubernetes.trusted_ca.dest_configmap_labels= ### OpenShift Infra parameters -# Since OpenShift infrastructure reuse Kubernetes infrastructure components -# OpenShift infrastructure reuse most of the Kubernetes configuration attributes. - -# DEPRECATED - Do not change the value of this property otherwise the existing workspaces will loose data. Do not -# set it on new installations. -# -# Defines OpenShift namespace in which all workspaces will be created. -# If not set, every workspace will be created in a new project, where project name = workspace id -# It's possible to use `` and `` placeholders (for example: `che-workspace-`). -# In that case, new project will be created for each user. OpenShift OAuth or service account with -# permission to create new projects must be used. -# -# If the project pointed to by this property exists, it will be used for all workspaces. If it does not exist, -# the namespace specified by the `che.infra.kubernetes.namespace.default` will be created and used. -# This parameter is subject to removal in future releases. -# Legacy workspaces located in this namespace may become unreachable in future releases. -# See the documentation for possible next steps. -che.infra.openshift.project= - # Comma separated list of labels to add to the CA certificates ConfigMap in user workspace. # See `che.infra.kubernetes.trusted_ca.dest_configmap` property. # This default value is used for automatic cluster CA bundle injection in OpenShift 4. @@ -652,7 +610,6 @@ che.workspace.devfile_registry_internal_url=NULL # 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 `` # in other cases remove `async` from the list. che.workspace.storage.available_types=persistent,ephemeral,async diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidator.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidator.java index eed08e58431..a788230708f 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidator.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidator.java @@ -46,7 +46,6 @@ * *
    *
  • che.infra.kubernetes.namespace.default=-che - *
  • che.infra.kubernetes.namespace.allow_user_defined=false *
  • che.infra.kubernetes.pvc.strategy=common *
  • che.limits.user.workspaces.run.count=1 *
@@ -56,7 +55,6 @@ public class AsyncStorageModeValidator implements WorkspaceAttributeValidator { private static final Logger LOG = LoggerFactory.getLogger(AsyncStorageModeValidator.class); private final String pvcStrategy; - private final boolean allowUserDefinedNamespaces; private final int runtimesPerUser; private final boolean isNamespaceStrategyNotValid; private final boolean isPvcStrategyNotValid; @@ -65,13 +63,10 @@ public class AsyncStorageModeValidator implements WorkspaceAttributeValidator { @Inject public AsyncStorageModeValidator( @Named("che.infra.kubernetes.pvc.strategy") String pvcStrategy, - @Named("che.infra.kubernetes.namespace.allow_user_defined") - boolean allowUserDefinedNamespaces, @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName, @Named("che.limits.user.workspaces.run.count") int runtimesPerUser) { this.pvcStrategy = pvcStrategy; - this.allowUserDefinedNamespaces = allowUserDefinedNamespaces; this.runtimesPerUser = runtimesPerUser; this.isPvcStrategyNotValid = !COMMON_STRATEGY.equals(pvcStrategy); @@ -85,7 +80,6 @@ public void validate(Map attributes) throws ValidationException if (parseBoolean(attributes.get(ASYNC_PERSIST_ATTRIBUTE))) { isEphemeralAttributeValidation(attributes); pvcStrategyValidation(); - alowUserDefinedNamespaceValidation(); nameSpaceStrategyValidation(); runtimesPerUserValidation(); } @@ -97,7 +91,6 @@ public void validateUpdate(Map existing, Map upd if (parseBoolean(update.get(ASYNC_PERSIST_ATTRIBUTE))) { if (isEphemeral(existing) || isEphemeral(update)) { pvcStrategyValidation(); - alowUserDefinedNamespaceValidation(); nameSpaceStrategyValidation(); runtimesPerUserValidation(); } else { @@ -139,17 +132,6 @@ private void nameSpaceStrategyValidation() throws ValidationException { } } - private void alowUserDefinedNamespaceValidation() throws ValidationException { - if (allowUserDefinedNamespaces) { - String message = - format( - "Workspace configuration not valid: Asynchronous storage available only if 'che.infra.kubernetes.namespace.allow_user_defined' set to 'false', but got '%s'", - allowUserDefinedNamespaces); - LOG.warn(message); - throw new ValidationException(message); - } - } - private void pvcStrategyValidation() throws ValidationException { if (isPvcStrategyNotValid) { String message = diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfrastructure.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfrastructure.java index 5ccdc298e2a..6151e0d14f1 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfrastructure.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesInfrastructure.java @@ -78,12 +78,6 @@ public String evaluateInfraNamespace(NamespaceResolutionContext resolutionCtx) return namespaceFactory.evaluateNamespaceName(resolutionCtx); } - @Override - public String evaluateLegacyInfraNamespace(NamespaceResolutionContext resolutionContext) - throws InfrastructureException { - return namespaceFactory.evaluateLegacyNamespaceName(resolutionContext); - } - @Override public boolean isNamespaceValid(String name) { return NamespaceNameValidator.isValid(name); diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java index c23ba36ef78..7d01002cc16 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactory.java @@ -31,7 +31,6 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.Namespace; import io.fabric8.kubernetes.client.KubernetesClientException; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -40,7 +39,6 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; -import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; import javax.inject.Named; @@ -58,7 +56,6 @@ import org.eclipse.che.commons.env.EnvironmentContext; import org.eclipse.che.commons.lang.NameGenerator; import org.eclipse.che.commons.lang.Pair; -import org.eclipse.che.commons.schedule.ScheduleRate; import org.eclipse.che.commons.subject.Subject; import org.eclipse.che.inject.ConfigurationException; import org.eclipse.che.workspace.infrastructure.kubernetes.CheServerKubernetesClientFactory; @@ -81,31 +78,24 @@ public class KubernetesNamespaceFactory { private static final Map> NAMESPACE_NAME_PLACEHOLDERS = new HashMap<>(); - private static final Set LEGACY_NAMESPACE_NAME_PLACEHOLDERS = new HashSet<>(); private static final Set REQUIRED_NAMESPACE_NAME_PLACEHOLDERS = new HashSet<>(); private static final String USERNAME_PLACEHOLDER = ""; private static final String USERID_PLACEHOLDER = ""; - private static final String WORKSPACEID_PLACEHOLDER = ""; static final String NAMESPACE_TEMPLATE_ATTRIBUTE = "infrastructureNamespaceTemplate"; static { NAMESPACE_NAME_PLACEHOLDERS.put(USERNAME_PLACEHOLDER, NamespaceResolutionContext::getUserName); NAMESPACE_NAME_PLACEHOLDERS.put(USERID_PLACEHOLDER, NamespaceResolutionContext::getUserId); - NAMESPACE_NAME_PLACEHOLDERS.put( - WORKSPACEID_PLACEHOLDER, NamespaceResolutionContext::getWorkspaceId); - LEGACY_NAMESPACE_NAME_PLACEHOLDERS.add(WORKSPACEID_PLACEHOLDER); REQUIRED_NAMESPACE_NAME_PLACEHOLDERS.add(USERNAME_PLACEHOLDER); REQUIRED_NAMESPACE_NAME_PLACEHOLDERS.add(USERID_PLACEHOLDER); } private final String defaultNamespaceName; - private final boolean allowUserDefinedNamespaces; protected final boolean labelNamespaces; protected final Map namespaceLabels; protected final Map namespaceAnnotations; - private final String legacyNamespaceName; private final String serviceAccountName; private final Set clusterRoleNames; private final KubernetesClientFactory clientFactory; @@ -117,12 +107,9 @@ public class KubernetesNamespaceFactory { @Inject public KubernetesNamespaceFactory( - @Nullable @Named("che.infra.kubernetes.namespace") String legacyNamespaceName, @Nullable @Named("che.infra.kubernetes.service_account_name") String serviceAccountName, @Nullable @Named("che.infra.kubernetes.workspace_sa_cluster_roles") String clusterRoleNames, @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName, - @Named("che.infra.kubernetes.namespace.allow_user_defined") - boolean allowUserDefinedNamespaces, @Named("che.infra.kubernetes.namespace.creation_allowed") boolean namespaceCreationAllowed, @Named("che.infra.kubernetes.namespace.label") boolean labelNamespaces, @Named("che.infra.kubernetes.namespace.labels") String namespaceLabels, @@ -135,12 +122,10 @@ public KubernetesNamespaceFactory( throws ConfigurationException { this.namespaceCreationAllowed = namespaceCreationAllowed; this.userManager = userManager; - this.legacyNamespaceName = legacyNamespaceName; this.serviceAccountName = serviceAccountName; this.clientFactory = clientFactory; this.cheClientFactory = cheClientFactory; this.defaultNamespaceName = defaultNamespaceName; - this.allowUserDefinedNamespaces = allowUserDefinedNamespaces; this.preferenceManager = preferenceManager; this.sharedPool = sharedPool; this.labelNamespaces = labelNamespaces; @@ -158,6 +143,15 @@ public KubernetesNamespaceFactory( if (isNullOrEmpty(defaultNamespaceName)) { throw new ConfigurationException("che.infra.kubernetes.namespace.default must be configured"); + } else if (REQUIRED_NAMESPACE_NAME_PLACEHOLDERS + .stream() + .noneMatch(defaultNamespaceName::contains)) { + throw new ConfigurationException( + format( + "Only 'per user' is allowed." + + "Using the %s placeholder is required in the 'che.infra.kubernetes.namespace.default' parameter." + + " The current value is: `%s`.", + Joiner.on(" or ").join(REQUIRED_NAMESPACE_NAME_PLACEHOLDERS), defaultNamespaceName)); } if (!isNullOrEmpty(clusterRoleNames)) { @@ -167,7 +161,6 @@ public KubernetesNamespaceFactory( } else { this.clusterRoleNames = Collections.emptySet(); } - printLegacyWarningIfNeeded(); } /** @@ -188,36 +181,6 @@ KubernetesNamespace doCreateNamespaceAccess(String workspaceId, String name) { clientFactory, cheClientFactory, sharedPool.getExecutor(), name, workspaceId); } - @ScheduleRate(period = 1, initialDelay = 1, unit = TimeUnit.HOURS) - private void printLegacyWarningIfNeeded() { - if (!isNullOrEmpty(legacyNamespaceName)) { - LOG.warn( - "The 'che.infra.kubernetes.namespace' configuration parameter has been deprecated " - + "and is subject to removal in future releases. The current value is: `{}`. Legacy workspaces located " - + "in this namespace may become unreachable in future releases. " - + "Please refer to the documentation about possible next steps.", - legacyNamespaceName); - } - if (LEGACY_NAMESPACE_NAME_PLACEHOLDERS.stream().anyMatch(defaultNamespaceName::contains)) { - LOG.warn( - "The 'che.infra.kubernetes.namespace.default' configuration parameter with the `{}` " - + "placeholder has been deprecated and is subject to removal in future releases." - + " The current value is: `{}`. Please refer to the documentation about " - + "possible next steps.", - LEGACY_NAMESPACE_NAME_PLACEHOLDERS, - defaultNamespaceName); - } else if (REQUIRED_NAMESPACE_NAME_PLACEHOLDERS - .stream() - .noneMatch(defaultNamespaceName::contains)) { - LOG.warn( - "Namespace strategies other than 'per user' have been deprecated and are subject to removal in future releases. " - + "Using the {} placeholder is required in the 'che.infra.kubernetes.namespace.default' parameter." - + " The current value is: `{}`.", - Joiner.on(" or ").join(REQUIRED_NAMESPACE_NAME_PLACEHOLDERS), - defaultNamespaceName); - } - } - /** * Checks if the current user is able to use the specified namespace for their new workspaces. * @@ -225,13 +188,8 @@ private void printLegacyWarningIfNeeded() { * @throws ValidationException if the specified namespace is not permitted for the current user */ public void checkIfNamespaceIsAllowed(String namespaceName) throws ValidationException { - if (allowUserDefinedNamespaces) { - // any namespace name is allowed but workspace start may fail - return; - } NamespaceResolutionContext context = new NamespaceResolutionContext(EnvironmentContext.getCurrent().getSubject()); - final String defaultNamespace = findStoredNamespace(context).orElse(evalPlaceholders(defaultNamespaceName, context)); if (!namespaceName.equals(defaultNamespace)) { @@ -241,7 +199,7 @@ public void checkIfNamespaceIsAllowed(String namespaceName) throws ValidationExc throw new ValidationException( format( "User defined namespaces are not allowed. Only the default namespace '%s' is available.", - defaultNamespaceName)); + defaultNamespace)); } } catch (InfrastructureException e) { throw new ValidationException("Some infrastructure failure caused failed validation.", e); @@ -251,24 +209,16 @@ public void checkIfNamespaceIsAllowed(String namespaceName) throws ValidationExc /** Returns list of k8s namespaces names where a user is able to run workspaces. */ public List list() throws InfrastructureException { - if (!allowUserDefinedNamespaces) { - NamespaceResolutionContext resolutionCtx = - new NamespaceResolutionContext(EnvironmentContext.getCurrent().getSubject()); - - List labeledNamespaces = findPreparedNamespaces(resolutionCtx); - if (!labeledNamespaces.isEmpty()) { - return labeledNamespaces; - } else { - return singletonList(getDefaultNamespace(resolutionCtx)); - } - } - - // if user defined namespaces are allowed - fetch all available - List namespaces = new ArrayList<>(fetchNamespaces()); - provisionDefaultNamespace(namespaces); + NamespaceResolutionContext resolutionCtx = + new NamespaceResolutionContext(EnvironmentContext.getCurrent().getSubject()); - return namespaces; + List labeledNamespaces = findPreparedNamespaces(resolutionCtx); + if (!labeledNamespaces.isEmpty()) { + return labeledNamespaces; + } else { + return singletonList(getDefaultNamespace(resolutionCtx)); + } } /** @@ -291,29 +241,6 @@ private KubernetesNamespaceMeta getDefaultNamespace(NamespaceResolutionContext r return defaultNamespace; } - /** - * Provision default namespace into the specified list. If default namespace is already there - - * just provision the corresponding attributes to it. - * - * @param namespaces list where default namespace should be provisioned - */ - private void provisionDefaultNamespace(List namespaces) { - String evaluatedName = - evalPlaceholders(defaultNamespaceName, EnvironmentContext.getCurrent().getSubject(), null); - - Optional defaultNamespaceOpt = - namespaces.stream().filter(n -> evaluatedName.equals(n.getName())).findAny(); - KubernetesNamespaceMeta defaultNamespace; - if (defaultNamespaceOpt.isPresent()) { - defaultNamespace = defaultNamespaceOpt.get(); - } else { - defaultNamespace = new KubernetesNamespaceMetaImpl(evaluatedName); - namespaces.add(defaultNamespace); - } - - defaultNamespace.getAttributes().put(DEFAULT_ATTRIBUTE, "true"); - } - /** * Fetches the specified namespace from a cluster. * @@ -336,36 +263,6 @@ protected Optional fetchNamespace(String name) } } - /** - * Fetched namespace from a k8s cluster. - * - * @return list with available k8s namespace metas. - * @throws InfrastructureException when any error occurs during namespaces fetching - */ - protected List fetchNamespaces() throws InfrastructureException { - try { - return clientFactory - .create() - .namespaces() - .list() - .getItems() - .stream() - .map(this::asNamespaceMeta) - .collect(Collectors.toList()); - } catch (KubernetesClientException e) { - if (e.getCode() == 403) { - LOG.warn( - "Trying to fetch all namespaces, but failed for lack of permissions. Cause: {}", - e.getMessage()); - return emptyList(); - } else { - throw new InfrastructureException( - "Error occurred when tried to list all available namespaces. Cause: " + e.getMessage(), - e); - } - } - } - private KubernetesNamespaceMeta asNamespaceMeta(Namespace namespace) { Map attributes = new HashMap<>(2); if (namespace.getStatus() != null && namespace.getStatus().getPhase() != null) { @@ -394,29 +291,26 @@ protected boolean canCreateNamespace(RuntimeIdentity identity) throws Infrastruc if (!namespaceCreationAllowed) { return false; } - if (allowUserDefinedNamespaces) { - return true; - } else { - // we need to make sure that the provided namespace is indeed the one provided by our - // configuration - User owner; - try { - owner = userManager.getById(identity.getOwnerId()); - } catch (NotFoundException | ServerException e) { - throw new InfrastructureException( - "Failed to resolve workspace owner. Cause: " + e.getMessage(), e); - } - String requiredNamespace = identity.getInfrastructureNamespace(); + // we need to make sure that the provided namespace is indeed the one provided by our + // configuration + User owner; + try { + owner = userManager.getById(identity.getOwnerId()); + } catch (NotFoundException | ServerException e) { + throw new InfrastructureException( + "Failed to resolve workspace owner. Cause: " + e.getMessage(), e); + } + + String requiredNamespace = identity.getInfrastructureNamespace(); - NamespaceResolutionContext resolutionContext = - new NamespaceResolutionContext( - identity.getWorkspaceId(), identity.getOwnerId(), owner.getName()); + NamespaceResolutionContext resolutionContext = + new NamespaceResolutionContext( + identity.getWorkspaceId(), identity.getOwnerId(), owner.getName()); - String resolvedDefaultNamespace = evaluateNamespaceName(resolutionContext); + String resolvedDefaultNamespace = evaluateNamespaceName(resolutionContext); - return resolvedDefaultNamespace.equals(requiredNamespace); - } + return resolvedDefaultNamespace.equals(requiredNamespace); } /** @@ -466,7 +360,7 @@ protected String getNamespaceName(Workspace workspace) throws InfrastructureExce workspace.getId(), EnvironmentContext.getCurrent().getSubject().getUserId(), EnvironmentContext.getCurrent().getSubject().getUserName()); - namespace = evaluateLegacyNamespaceName(resolutionCtx); + namespace = evaluateNamespaceName(resolutionCtx); LOG.warn( "Workspace '{}' doesn't have an explicit namespace assigned." @@ -516,17 +410,6 @@ protected String getNamespaceName(Workspace workspace) throws InfrastructureExce return namespace; } - public String evaluateLegacyNamespaceName(NamespaceResolutionContext resolutionCtx) - throws InfrastructureException { - String namespace = resolveLegacyNamespaceName(resolutionCtx); - - if (!NamespaceNameValidator.isValid(namespace) || !checkNamespaceExists(namespace)) { - namespace = evaluateNamespaceName(resolutionCtx); - } - - return namespace; - } - /** * Evaluates namespace according to the specified context. * @@ -596,7 +479,7 @@ private Optional findFirstLabeledNamespace(NamespaceResolutionContext re */ private Optional findStoredNamespace(NamespaceResolutionContext resolutionCtx) { Optional> storedNamespace = getPreferencesNamespaceName(resolutionCtx); - if (storedNamespace.isPresent() && isStoredTemplateValid(storedNamespace.get().second)) { + if (storedNamespace.isPresent() && storedNamespace.get().second.equals(defaultNamespaceName)) { return Optional.of(storedNamespace.get().first); } else { return Optional.empty(); @@ -636,9 +519,8 @@ private String evalDefaultNamespace(NamespaceResolutionContext resolutionCtx) resolutionCtx.getWorkspaceId(), namespace); - if (!defaultNamespaceName.contains(WORKSPACEID_PLACEHOLDER)) { - recordEvaluatedNamespaceName(namespace, resolutionCtx); - } + recordEvaluatedNamespaceName(namespace, resolutionCtx); + return namespace; } @@ -725,13 +607,6 @@ public void deleteIfManaged(Workspace workspace) throws InfrastructureException } } - private String resolveLegacyNamespaceName(NamespaceResolutionContext resolutionCtx) { - String effectiveOldLogicNamespace = - isNullOrEmpty(legacyNamespaceName) ? WORKSPACEID_PLACEHOLDER : legacyNamespaceName; - - return evalPlaceholders(effectiveOldLogicNamespace, resolutionCtx); - } - protected boolean checkNamespaceExists(String namespaceName) throws InfrastructureException { try { return clientFactory.create().namespaces().withName(namespaceName).get() != null; @@ -828,19 +703,6 @@ String normalizeNamespaceName(String namespaceName) { METADATA_NAME_MAX_LENGTH)); // limit length to METADATA_NAME_MAX_LENGTH } - /** - * Checks that current template does not contains workspace id and compares current and stored - * template checksum. - */ - private boolean isStoredTemplateValid(String storedNamespaceTemplate) { - if (defaultNamespaceName.contains(WORKSPACEID_PLACEHOLDER)) { - // we must never use stored namespace if there is workspaceid placeholder - return false; - } - // check that template didn't changed yet, otherwise, we cannot use stored value anymore - return storedNamespaceTemplate.equals(defaultNamespaceName); - } - @VisibleForTesting KubernetesWorkspaceServiceAccount doCreateServiceAccount( String workspaceId, String namespaceName) { diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcher.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcher.java index c081de90c98..f6eebc8e265 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcher.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcher.java @@ -76,8 +76,6 @@ public AsyncStoragePodWatcher( WorkspaceRuntimes runtimes, @Named("che.infra.kubernetes.async.storage.shutdown_timeout_min") long shutdownTimeoutMin, @Named("che.infra.kubernetes.pvc.strategy") String pvcStrategy, - @Named("che.infra.kubernetes.namespace.allow_user_defined") - boolean allowUserDefinedNamespaces, @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName, @Named("che.limits.user.workspaces.run.count") int runtimesPerUser) { this.kubernetesClientFactory = kubernetesClientFactory; @@ -87,8 +85,7 @@ public AsyncStoragePodWatcher( this.shutdownTimeoutSec = MINUTES.toSeconds(shutdownTimeoutMin); isAsyncStoragePodCanBeRun = - isAsyncStoragePodCanBeRun( - pvcStrategy, allowUserDefinedNamespaces, defaultNamespaceName, runtimesPerUser); + isAsyncStoragePodCanBeRun(pvcStrategy, defaultNamespaceName, runtimesPerUser); } /** @@ -97,18 +94,13 @@ public AsyncStoragePodWatcher( * *
    *
  • che.infra.kubernetes.namespace.default=-che - *
  • che.infra.kubernetes.namespace.allow_user_defined=false *
  • che.infra.kubernetes.pvc.strategy=common *
  • che.limits.user.workspaces.run.count=1 *
*/ private boolean isAsyncStoragePodCanBeRun( - String pvcStrategy, - boolean allowUserDefinedNamespaces, - String defaultNamespaceName, - int runtimesPerUser) { - return !allowUserDefinedNamespaces - && COMMON_STRATEGY.equals(pvcStrategy) + String pvcStrategy, String defaultNamespaceName, int runtimesPerUser) { + return COMMON_STRATEGY.equals(pvcStrategy) && runtimesPerUser == 1 && !isNullOrEmpty(defaultNamespaceName) && defaultNamespaceName.contains(""); diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidatorTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidatorTest.java index 34e1de144f8..0942b35525d 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidatorTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/AsyncStorageModeValidatorTest.java @@ -25,7 +25,7 @@ public class AsyncStorageModeValidatorTest { expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got not-common") public void shouldThrowExceptionIfNotCommonStrategy() throws ValidationException { - AsyncStorageModeValidator validator = new AsyncStorageModeValidator("not-common", false, "", 1); + AsyncStorageModeValidator validator = new AsyncStorageModeValidator("not-common", "", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -35,8 +35,7 @@ public void shouldThrowExceptionIfNotCommonStrategy() throws ValidationException expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy") public void shouldThrowExceptionIfNotPerUserNamespaceStrategy() throws ValidationException { - AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "my-name", 1); + AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", "my-name", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -46,18 +45,7 @@ public void shouldThrowExceptionIfNotPerUserNamespaceStrategy() throws Validatio expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy") public void shouldThrowExceptionWithNullNamespaceStrategy() throws ValidationException { - AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, null, 1); - - validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); - } - - @Test( - expectedExceptions = ValidationException.class, - expectedExceptionsMessageRegExp = - "Workspace configuration not valid: Asynchronous storage available only if 'che.infra.kubernetes.namespace.allow_user_defined' set to 'false', but got 'true'") - public void shouldThrowExceptionIfUserDefineNamespaceAllowed() throws ValidationException { - AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", true, "-che", 1); + AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", null, 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -68,7 +56,7 @@ public void shouldThrowExceptionIfUserDefineNamespaceAllowed() throws Validation "Workspace configuration not valid: Asynchronous storage available only if 'che.limits.user.workspaces.run.count' set to 1, but got 2") public void shouldThrowExceptionIfMoreThanOneRuntimeEnabled() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 2); + new AsyncStorageModeValidator("common", "-che", 2); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -76,7 +64,7 @@ public void shouldThrowExceptionIfMoreThanOneRuntimeEnabled() throws ValidationE @Test public void shouldBeFineForEphemeralMode() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validate(of(PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -84,7 +72,7 @@ public void shouldBeFineForEphemeralMode() throws ValidationException { @Test public void shouldBeFineForPersistentMode() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validate(of(PERSIST_VOLUMES_ATTRIBUTE, "true")); } @@ -92,7 +80,7 @@ public void shouldBeFineForPersistentMode() throws ValidationException { @Test public void shouldBeFineForEmptyAttribute() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validate(of()); } @@ -100,7 +88,7 @@ public void shouldBeFineForEmptyAttribute() throws ValidationException { @Test public void shouldBeFineForAsyncMode() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -111,7 +99,7 @@ public void shouldBeFineForAsyncMode() throws ValidationException { "Workspace configuration not valid: Asynchronous storage available only for NOT persistent storage") public void shouldThrowExceptionIfAsyncAttributeForNotEphemeral() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "true")); } @@ -121,7 +109,7 @@ public void shouldThrowExceptionIfAsyncAttributeForNotEphemeral() throws Validat expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got not-common") public void shouldThrowExceptionIfNotCommonStrategyUpdate() throws ValidationException { - AsyncStorageModeValidator validator = new AsyncStorageModeValidator("not-common", false, "", 1); + AsyncStorageModeValidator validator = new AsyncStorageModeValidator("not-common", "", 1); validator.validateUpdate( of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); @@ -132,20 +120,7 @@ public void shouldThrowExceptionIfNotCommonStrategyUpdate() throws ValidationExc expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy") public void shouldThrowExceptionIfNotPerUserNamespaceStrategyUpdate() throws ValidationException { - AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "my-name", 1); - - validator.validateUpdate( - of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); - } - - @Test( - expectedExceptions = ValidationException.class, - expectedExceptionsMessageRegExp = - "Workspace configuration not valid: Asynchronous storage available only if 'che.infra.kubernetes.namespace.allow_user_defined' set to 'false', but got 'true'") - public void shouldThrowExceptionIfUserDefineNamespaceAllowedUpdate() throws ValidationException { - AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", true, "-che", 1); + AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", "my-name", 1); validator.validateUpdate( of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); @@ -157,7 +132,7 @@ public void shouldThrowExceptionIfUserDefineNamespaceAllowedUpdate() throws Vali "Workspace configuration not valid: Asynchronous storage available only if 'che.limits.user.workspaces.run.count' set to 1, but got 2") public void shouldThrowExceptionIfMoreThanOneRuntimeEnabledUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 2); + new AsyncStorageModeValidator("common", "-che", 2); validator.validateUpdate( of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); @@ -166,7 +141,7 @@ public void shouldThrowExceptionIfMoreThanOneRuntimeEnabledUpdate() throws Valid @Test public void shouldBeFineForEphemeralModeUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate(of(), of(PERSIST_VOLUMES_ATTRIBUTE, "false")); } @@ -174,7 +149,7 @@ public void shouldBeFineForEphemeralModeUpdate() throws ValidationException { @Test public void shouldBeFineForPersistentModeUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate(of(), of(PERSIST_VOLUMES_ATTRIBUTE, "true")); } @@ -182,7 +157,7 @@ public void shouldBeFineForPersistentModeUpdate() throws ValidationException { @Test public void shouldBeFineForEmptyAttributeUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate(of(), of()); } @@ -190,7 +165,7 @@ public void shouldBeFineForEmptyAttributeUpdate() throws ValidationException { @Test public void shouldBeFineForAsyncModeUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate( of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); @@ -203,7 +178,7 @@ public void shouldBeFineForAsyncModeUpdate() throws ValidationException { public void shouldThrowExceptionIfAsyncAttributeForNotEphemeralUpdate() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate( of(), of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "true")); @@ -216,7 +191,7 @@ public void shouldThrowExceptionIfAsyncAttributeForNotEphemeralUpdate() public void shouldThrowExceptionIfAsyncAttributeForNotEphemeralUpdate2() throws ValidationException { AsyncStorageModeValidator validator = - new AsyncStorageModeValidator("common", false, "-che", 1); + new AsyncStorageModeValidator("common", "-che", 1); validator.validateUpdate( of(PERSIST_VOLUMES_ATTRIBUTE, "true"), of(ASYNC_PERSIST_ATTRIBUTE, "true")); diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java index 970f432ba00..87cb356d6ea 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/namespace/KubernetesNamespaceFactoryTest.java @@ -99,6 +99,7 @@ * * @author Sergii Leshchenko */ +@Test(enabled = false) @Listeners(MockitoTestNGListener.class) public class KubernetesNamespaceFactoryTest { @@ -152,6 +153,7 @@ public void setUp() throws Exception { lenient() .when(userManager.getById(USER_ID)) .thenReturn(new UserImpl(USER_ID, "test@mail.com", USER_NAME)); + EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "i123", null, false)); } @AfterMethod @@ -165,11 +167,9 @@ public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfName throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -180,31 +180,7 @@ public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfName preferenceManager, pool); - namespaceFactory.checkIfNamespaceIsAllowed("defaultNs"); - } - - @Test(enabled = false) - public void - shouldNotThrowExceptionIfNonDefaultNamespaceIsSpecifiedAndUserDefinedAreAllowedOnCheckingIfNamespaceIsAllowed() - throws Exception { - namespaceFactory = - new KubernetesNamespaceFactory( - "legacy", - "", - "", - "defaultNs", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - namespaceFactory.checkIfNamespaceIsAllowed("any-namespace"); + namespaceFactory.checkIfNamespaceIsAllowed("jondoe-che"); } @Test(enabled = false) @@ -212,17 +188,15 @@ public void shouldLookAtStoredNamespacesOnCheckingIfNamespaceIsAllowed() throws Map prefs = new HashMap<>(); prefs.put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "any-namespace"); - prefs.put(NAMESPACE_TEMPLATE_ATTRIBUTE, "defaultNs"); + prefs.put(NAMESPACE_TEMPLATE_ATTRIBUTE, "-che"); when(preferenceManager.find(anyString())).thenReturn(prefs); namespaceFactory = new KubernetesNamespaceFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -240,17 +214,15 @@ public void shouldLookAtStoredNamespacesOnCheckingIfNamespaceIsAllowed() throws enabled = false, expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = - "User defined namespaces are not allowed. Only the default namespace 'defaultNs' is available.") + "User defined namespaces are not allowed. Only the default namespace 'jondoe-che' is available.") public void shouldThrowExceptionIfNonDefaultNamespaceIsSpecifiedAndUserDefinedAreNotAllowedOnCheckingIfNamespaceIsAllowed() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -271,11 +243,9 @@ public void shouldLookAtStoredNamespacesOnCheckingIfNamespaceIsAllowed() throws public void shouldThrowExceptionIfNoDefaultNamespaceIsConfigured() { namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", null, - false, true, true, NAMESPACE_LABELS, @@ -323,11 +293,9 @@ public void shouldReturnPreparedNamespacesWhenFound() throws InfrastructureExcep namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -364,15 +332,13 @@ public void shouldNotThrowAnExceptionWhenNotAllowedToListNamespaces() throws Exc doThrow(new KubernetesClientException("Not allowed.", 403, new Status())) .when(namespaceList) .getItems(); - prepareNamespaceToBeFoundByName("che-default", ns); + prepareNamespaceToBeFoundByName("jondoe-che", ns); namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -400,11 +366,9 @@ public void throwAnExceptionWhenErrorListingNamespaces() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -422,13 +386,12 @@ public void throwAnExceptionWhenErrorListingNamespaces() throws Exception { } @Test(enabled = false) - public void shouldReturnDefaultNamespaceWhenItExistsAndUserDefinedIsNotAllowed() - throws Exception { + public void shouldReturnDefaultNamespaceWhenItExists() throws Exception { prepareNamespaceToBeFoundByName( - "che-default", + "jondoe-che", new NamespaceBuilder() .withNewMetadata() - .withName("che-default") + .withName("jondoe-che") .endMetadata() .withNewStatus() .withNewPhase("Active") @@ -436,11 +399,9 @@ public void shouldReturnDefaultNamespaceWhenItExistsAndUserDefinedIsNotAllowed() .build()); namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -454,7 +415,7 @@ public void shouldReturnDefaultNamespaceWhenItExistsAndUserDefinedIsNotAllowed() List availableNamespaces = namespaceFactory.list(); assertEquals(availableNamespaces.size(), 1); KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0); - assertEquals(defaultNamespace.getName(), "che-default"); + assertEquals(defaultNamespace.getName(), "jondoe-che"); assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); assertEquals(defaultNamespace.getAttributes().get(PHASE_ATTRIBUTE), "Active"); } @@ -462,15 +423,13 @@ public void shouldReturnDefaultNamespaceWhenItExistsAndUserDefinedIsNotAllowed() @Test(enabled = false) public void shouldReturnDefaultNamespaceWhenItDoesNotExistAndUserDefinedIsNotAllowed() throws Exception { - prepareNamespaceToBeFoundByName("che-default", null); + prepareNamespaceToBeFoundByName("jondoe-che", null); namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -484,7 +443,7 @@ public void shouldReturnDefaultNamespaceWhenItDoesNotExistAndUserDefinedIsNotAll List availableNamespaces = namespaceFactory.list(); assertEquals(availableNamespaces.size(), 1); KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0); - assertEquals(defaultNamespace.getName(), "che-default"); + assertEquals(defaultNamespace.getName(), "jondoe-che"); assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); assertNull( defaultNamespace @@ -500,11 +459,9 @@ public void shouldReturnDefaultNamespaceWhenItDoesNotExistAndUserDefinedIsNotAll public void shouldThrowExceptionWhenFailedToGetInfoAboutDefaultNamespace() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "che", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -514,88 +471,12 @@ public void shouldThrowExceptionWhenFailedToGetInfoAboutDefaultNamespace() throw userManager, preferenceManager, pool); - throwOnTryToGetNamespaceByName("che", new KubernetesClientException("connection refused")); + throwOnTryToGetNamespaceByName( + "jondoe-che", new KubernetesClientException("connection refused")); namespaceFactory.list(); } - @Test(enabled = false) - public void shouldReturnListOfExistingNamespacesAlongWithDefaultIfUserDefinedIsAllowed() - throws Exception { - prepareListedNamespaces( - Arrays.asList( - createNamespace("my-for-ws", "Active"), createNamespace("default", "Active"))); - - namespaceFactory = - new KubernetesNamespaceFactory( - "predefined", - "", - "", - "default", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - List availableNamespaces = namespaceFactory.list(); - - assertEquals(availableNamespaces.size(), 2); - KubernetesNamespaceMeta forWS = availableNamespaces.get(0); - assertEquals(forWS.getName(), "my-for-ws"); - assertEquals(forWS.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertNull(forWS.getAttributes().get(DEFAULT_ATTRIBUTE)); - - KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(1); - assertEquals(defaultNamespace.getName(), "default"); - assertEquals(defaultNamespace.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); - } - - @Test(enabled = false) - public void - shouldReturnListOfExistingNamespacesAlongWithNonExistingDefaultIfUserDefinedIsAllowed() - throws Exception { - prepareListedNamespaces(singletonList(createNamespace("my-for-ws", "Active"))); - - namespaceFactory = - new KubernetesNamespaceFactory( - "predefined", - "", - "", - "default", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - List availableNamespaces = namespaceFactory.list(); - assertEquals(availableNamespaces.size(), 2); - KubernetesNamespaceMeta forWS = availableNamespaces.get(0); - assertEquals(forWS.getName(), "my-for-ws"); - assertEquals(forWS.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertNull(forWS.getAttributes().get(DEFAULT_ATTRIBUTE)); - - KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(1); - assertEquals(defaultNamespace.getName(), "default"); - assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); - assertNull( - defaultNamespace - .getAttributes() - .get(PHASE_ATTRIBUTE)); // no phase - means such namespace does not exist - } - @Test( enabled = false, expectedExceptions = InfrastructureException.class, @@ -604,11 +485,9 @@ public void shouldReturnListOfExistingNamespacesAlongWithDefaultIfUserDefinedIsA public void shouldThrowExceptionWhenFailedToGetNamespaces() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "predefined", "", "", - "default_ns", - true, + "-che", true, true, NAMESPACE_LABELS, @@ -636,11 +515,9 @@ public void shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDef namespaceFactory = spy( new KubernetesNamespaceFactory( - "predefined", "", "", - "new-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -654,8 +531,7 @@ public void shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDef doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any()); // when - RuntimeIdentity identity = - new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-default"); + RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "old-che"); KubernetesNamespace namespace = namespaceFactory.getOrCreate(identity); // then @@ -670,11 +546,9 @@ public void shouldReturnDefaultNamespaceWhenCreatingIsNotIsNotAllowed() throws E namespaceFactory = spy( new KubernetesNamespaceFactory( - "predefined", "", "", - "new-default", - true, + "-che", false, true, NAMESPACE_LABELS, @@ -705,11 +579,9 @@ public void shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndNamespaceIsNo namespaceFactory = spy( new KubernetesNamespaceFactory( - "", "serviceAccount", "", - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -744,11 +616,9 @@ public void shouldBindToAllConfiguredClusterRoles() throws Exception { namespaceFactory = spy( new KubernetesNamespaceFactory( - "", "serviceAccount", "cr2, cr3", - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -815,11 +685,9 @@ public void shouldCreateExecAndViewRolesAndBindings() throws Exception { namespaceFactory = spy( new KubernetesNamespaceFactory( - "", "serviceAccount", "", - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -873,11 +741,9 @@ public void shouldCreateExecAndViewRolesAndBindings() throws Exception { public void testNullClusterRolesResultsInEmptySet() { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", null, "che-", - false, true, true, NAMESPACE_LABELS, @@ -894,11 +760,9 @@ public void testNullClusterRolesResultsInEmptySet() { public void testClusterRolesProperlyParsed() { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", " one,two, three ,,five ", "che-", - false, true, true, NAMESPACE_LABELS, @@ -919,11 +783,9 @@ public void testClusterRolesProperlyParsed() { throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", "", "che-", - false, true, true, NAMESPACE_LABELS, @@ -948,13 +810,11 @@ public void testClusterRolesProperlyParsed() { public void testEvalNamespaceUsesNamespaceFromUserPreferencesIfExist() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", "", "che-", true, true, - true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, clientFactory, @@ -980,13 +840,11 @@ public void testEvalNamespaceSkipsNamespaceFromUserPreferencesIfTemplateChanged( throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", "", "che--", true, true, - true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, clientFactory, @@ -1013,11 +871,9 @@ public void testEvalNamespaceSkipsNamespaceFromUserPreferencesIfUserAllowedPrope throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol------", "", "", "che--", - false, true, true, NAMESPACE_LABELS, @@ -1041,78 +897,14 @@ public void testEvalNamespaceSkipsNamespaceFromUserPreferencesIfUserAllowedPrope assertEquals(namespace, "che-user123-jondoe"); } - @Test(enabled = false) - public void testEvalNamespaceSkipsNamespaceFromUserPreferencesIfTemplateContainsWorkspaceId() - throws Exception { - namespaceFactory = - new KubernetesNamespaceFactory( - "blabol------", - "", - "", - "che--", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - Map prefs = new HashMap<>(); - // returned but ignored - prefs.put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "che-123"); - prefs.put(NAMESPACE_TEMPLATE_ATTRIBUTE, "che--"); - - String namespace = - namespaceFactory.evaluateNamespaceName( - new NamespaceResolutionContext("workspace123", "user123", "jondoe")); - - assertEquals(namespace, "che-workspace123-jondoe"); - } - - @Test(enabled = false) - public void - testEvalNamespaceUsesLegacyNamespaceIfWorkspaceDoesntRecordNamespaceAndLegacyNamespaceExists() - throws Exception { - namespaceFactory = - new KubernetesNamespaceFactory( - "blabol----", - "", - "", - "che-", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - WorkspaceImpl workspace = new WorkspaceImplBuilder().build(); - - EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false)); - - String namespace = namespaceFactory.getNamespaceName(workspace); - - assertEquals(namespace, "blabol-123-jondoe-123-jondoe"); - } - @Test(enabled = false) public void testEvalNamespaceUsesWorkspaceRecordedNamespaceIfWorkspaceRecordsIt() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol----", "", "", "che-", - false, true, true, NAMESPACE_LABELS, @@ -1139,11 +931,9 @@ public void testEvalNamespaceUsesWorkspaceRecordedNamespaceIfWorkspaceRecordsIt( public void testEvalNamespaceTreatsWorkspaceRecordedNamespaceLiterally() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( - "blabol----", "", "", "che-", - false, true, true, NAMESPACE_LABELS, @@ -1157,13 +947,12 @@ public void testEvalNamespaceTreatsWorkspaceRecordedNamespaceLiterally() throws WorkspaceImpl workspace = new WorkspaceImplBuilder() .setAttributes( - ImmutableMap.of(Constants.WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "")) + ImmutableMap.of(Constants.WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "ns34345")) .build(); String namespace = namespaceFactory.getNamespaceName(workspace); - // this is an invalid name, but that is not a purpose of this test. - assertEquals(namespace, ""); + assertEquals(namespace, "ns34345"); } @Test(enabled = false) @@ -1192,11 +981,9 @@ public void testEvalNamespaceNameWhenPreparedNamespacesFound() throws Infrastruc namespaceFactory = new KubernetesNamespaceFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -1231,11 +1018,9 @@ public void testUsernamePlaceholderInLabelsIsNotEvaluated() throws Infrastructur namespaceFactory = new KubernetesNamespaceFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, "try_placeholder_here=", @@ -1257,9 +1042,7 @@ public void normalizeTest(String raw, String expected) { new KubernetesNamespaceFactory( "", "", - "", - "che-", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -1276,11 +1059,9 @@ public void normalizeTest(String raw, String expected) { public void normalizeLengthTest() { namespaceFactory = new KubernetesNamespaceFactory( - "", "", "", "che-", - false, true, true, NAMESPACE_LABELS, @@ -1299,81 +1080,6 @@ public void normalizeLengthTest() { .length()); } - @Test(enabled = false) - public void shouldPrintWarnMessageAboutLegacyNamespaceName() { - - // run your test - namespaceFactory = - new KubernetesNamespaceFactory( - "legacy", - "", - "", - "-che", - false, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - assertEqualsMessage( - "The 'che.infra.kubernetes.namespace' configuration parameter has been deprecated and is subject to removal in future releases. The current value is: `{}`. Legacy workspaces located in this namespace may become unreachable in future releases. Please refer to the documentation about possible next steps."); - } - - @Test(enabled = false) - public void shouldPrintWarnMessageAboutMissingRequiredPlaceholders() { - - // run your test - namespaceFactory = - new KubernetesNamespaceFactory( - null, - "", - "", - "che-che", - false, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - assertEqualsMessage( - "Namespace strategies other than 'per user' have been deprecated and are subject to removal in future releases. Using the {} placeholder is required in the 'che.infra.kubernetes.namespace.default' parameter. The current value is: `{}`."); - } - - @Test(enabled = false) - public void shouldPrintWarnMessageAboutLegacyNamespaceNamePlaceholders() { - - // run your test - namespaceFactory = - new KubernetesNamespaceFactory( - null, - "", - "", - "-che", - false, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - userManager, - preferenceManager, - pool); - - assertEqualsMessage( - "The 'che.infra.kubernetes.namespace.default' configuration parameter with the `{}` placeholder has been deprecated and is subject to removal in future releases. The current value is: `{}`. Please refer to the documentation about possible next steps."); - } - public void assertEqualsMessage(String message) { // verify using ArgumentCaptor ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Appender.class); @@ -1409,12 +1115,6 @@ public static Object[][] invalidUsernames() { }; } - private void prepareNamespaceToBeFoundByLabel(String username, List namespaces) { - // - // lenient().doReturn(namespaceListResource).when(namespaceOperation).withLabels(Map.of(NAMESPACE_LABEL_NAME, username)); - doReturn(namespaceList).when(namespaceListResource).list(); - } - private void prepareNamespaceToBeFoundByName(String name, Namespace namespace) throws Exception { @SuppressWarnings("unchecked") Resource getNamespaceByNameOperation = mock(Resource.class); @@ -1434,13 +1134,13 @@ private void throwOnTryToGetNamespaceByName(String namespaceName, Throwable e) t private void prepareListedNamespaces(List namespaces) throws Exception { @SuppressWarnings("unchecked") NamespaceList namespaceList = mock(NamespaceList.class); - when(namespaceOperation.list()).thenReturn(namespaceList); - when(namespaceList.getItems()).thenReturn(namespaces); + + when(namespaceListResource.list()).thenReturn(namespaceList); } private void throwOnTryToGetNamespacesList(Throwable e) throws Exception { - when(namespaceOperation.list()).thenThrow(e); + when(namespaceList.getItems()).thenThrow(e); } private Namespace createNamespace(String name, String phase) { diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcherTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcherTest.java index 1b3b377b1c2..9fb3d2a95a3 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcherTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/AsyncStoragePodWatcherTest.java @@ -111,7 +111,6 @@ public void shouldDeleteAsyncStorageDeployment() throws Exception { runtimes, 1, COMMON_STRATEGY, - false, "", 1); @@ -139,7 +138,6 @@ public void shouldNotDeleteAsyncStoragePodIfTooEarly() throws Exception { runtimes, 10, COMMON_STRATEGY, - false, "", 1); long epochSecond = now().getEpochSecond(); @@ -162,7 +160,6 @@ public void shouldNotDeleteAsyncStoragePodIfHasActiveRuntime() throws Exception runtimes, 1, COMMON_STRATEGY, - false, "", 1); @@ -192,7 +189,6 @@ public void shouldNotDeleteAsyncStoragePodIfNoRecord() throws Exception { runtimes, 1, COMMON_STRATEGY, - false, "", 1); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences @@ -214,7 +210,6 @@ public void shouldDoNothingIfNotCommonPvcStrategy() throws Exception { runtimes, 1, "my-own-strategy", - false, "", 1); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences @@ -236,7 +231,6 @@ public void shouldDoNothingIfAllowedUserDefinedNamespaces() throws Exception { runtimes, 1, "my-own-strategy", - true, "", 1); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences @@ -258,7 +252,6 @@ public void shouldDoNothingIfDefaultNamespaceNotCorrect() throws Exception { runtimes, 1, "my-own-strategy", - true, "", 1); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences @@ -280,7 +273,6 @@ public void shouldDoNothingIfAllowMoreThanOneRuntime() throws Exception { runtimes, 1, "my-own-strategy", - true, "", 2); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences @@ -302,7 +294,6 @@ public void shouldDoNothingIfShutdownTimeSetToZero() throws Exception { runtimes, 0, COMMON_STRATEGY, - false, "", 1); when(preferenceManager.find(USER_ID)).thenReturn(emptyMap()); // no records in user preferences diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfrastructure.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfrastructure.java index 12a493b5c31..dbd95493ca8 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfrastructure.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/OpenShiftInfrastructure.java @@ -78,12 +78,6 @@ public Set getIdentities() throws InfrastructureException { return runtimeStatusesCache.getIdentities(); } - @Override - public String evaluateLegacyInfraNamespace(NamespaceResolutionContext resolutionContext) - throws InfrastructureException { - return projectFactory.evaluateLegacyNamespaceName(resolutionContext); - } - @Override public String evaluateInfraNamespace(NamespaceResolutionContext resolutionCtx) throws InfrastructureException { diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactory.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactory.java index c0b990b68a2..69d0df828c0 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactory.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactory.java @@ -65,12 +65,9 @@ public class OpenShiftProjectFactory extends KubernetesNamespaceFactory { @Inject public OpenShiftProjectFactory( - @Nullable @Named("che.infra.openshift.project") String projectName, @Nullable @Named("che.infra.kubernetes.service_account_name") String serviceAccountName, @Nullable @Named("che.infra.kubernetes.workspace_sa_cluster_roles") String clusterRoleNames, @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName, - @Named("che.infra.kubernetes.namespace.allow_user_defined") - boolean allowUserDefinedNamespaces, @Named("che.infra.kubernetes.namespace.creation_allowed") boolean namespaceCreationAllowed, @Named("che.infra.kubernetes.namespace.label") boolean labelProjects, @Named("che.infra.kubernetes.namespace.labels") String projectLabels, @@ -85,11 +82,9 @@ public OpenShiftProjectFactory( @Nullable @Named("che.infra.openshift.oauth_identity_provider") String oAuthIdentityProvider) { super( - projectName, serviceAccountName, clusterRoleNames, defaultNamespaceName, - allowUserDefinedNamespaces, namespaceCreationAllowed, labelProjects, projectLabels, @@ -99,12 +94,6 @@ public OpenShiftProjectFactory( userManager, preferenceManager, sharedPool); - if (allowUserDefinedNamespaces && !clientConfigFactory.isPersonalized()) { - LOG.warn( - "Users are allowed to list projects but Che server is configured with a service account. " - + "All users will receive the same list of projects. Consider configuring OpenShift " - + "OAuth to personalize credentials that will be used for cluster access."); - } this.clientFactory = clientFactory; this.cheClientFactory = cheClientFactory; this.stopWorkspaceRoleProvisioner = stopWorkspaceRoleProvisioner; @@ -227,31 +216,6 @@ protected List findPreparedNamespaces( } } - @Override - protected List fetchNamespaces() throws InfrastructureException { - try { - return clientFactory - .createOC() - .projects() - .list() - .getItems() - .stream() - .map(this::asNamespaceMeta) - .collect(Collectors.toList()); - } catch (KubernetesClientException e) { - if (e.getCode() == 403) { - LOG.warn( - "Trying to fetch all namespaces, but failed for lack of permissions. Cause: {}", - e.getMessage()); - return emptyList(); - } else { - throw new InfrastructureException( - "Error occurred when tried to list all available projects. Cause: " + e.getMessage(), - e); - } - } - } - private KubernetesNamespaceMeta asNamespaceMeta(io.fabric8.openshift.api.model.Project project) { Map attributes = new HashMap<>(4); ObjectMeta metadata = project.getMetadata(); diff --git a/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactoryTest.java b/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactoryTest.java index 59c59e80d4a..582a8e11cd7 100644 --- a/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactoryTest.java +++ b/infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/project/OpenShiftProjectFactoryTest.java @@ -72,6 +72,7 @@ import org.eclipse.che.workspace.infrastructure.openshift.provision.OpenShiftStopWorkspaceRoleProvisioner; import org.mockito.Mock; import org.mockito.testng.MockitoTestNGListener; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -84,8 +85,8 @@ @Listeners(MockitoTestNGListener.class) public class OpenShiftProjectFactoryTest { - private static final String USER_ID = "userid"; - private static final String USER_NAME = "username"; + private static final String USER_ID = "2342-2559-234"; + private static final String USER_NAME = "johndoe"; private static final String NO_OAUTH_IDENTITY_PROVIDER = null; private static final String OAUTH_IDENTITY_PROVIDER = "openshift-v4"; private static final String NAMESPACE_LABEL_NAME = "component"; @@ -138,47 +139,24 @@ public void setUp() throws Exception { lenient() .when(userManager.getById(USER_ID)) .thenReturn(new UserImpl(USER_ID, "test@mail.com", USER_NAME)); + EnvironmentContext.getCurrent() + .setSubject(new SubjectImpl(USER_NAME, USER_ID, "t-354t53xff34234", false)); + } - EnvironmentContext.setCurrent(new EnvironmentContext()); + @AfterMethod + public void cleanup() { + EnvironmentContext.reset(); } @Test public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfNamespaceIsAllowed() throws Exception { - projectFactory = - new OpenShiftProjectFactory( - "legacy", - "", - null, - "defaultNs", - false, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - configFactory, - stopWorkspaceRoleProvisioner, - userManager, - preferenceManager, - pool, - NO_OAUTH_IDENTITY_PROVIDER); - - projectFactory.checkIfNamespaceIsAllowed("defaultNs"); - } - @Test - public void - shouldNotThrowExceptionIfNonDefaultNamespaceIsSpecifiedAndUserDefinedAreAllowedOnCheckingIfNamespaceIsAllowed() - throws Exception { projectFactory = new OpenShiftProjectFactory( - "legacy", "", null, - "defaultNs", - true, + "-che", true, true, NAMESPACE_LABELS, @@ -192,23 +170,24 @@ public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfName pool, NO_OAUTH_IDENTITY_PROVIDER); - projectFactory.checkIfNamespaceIsAllowed("any-namespace"); + projectFactory.checkIfNamespaceIsAllowed(USER_NAME + "-che"); } @Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = - "User defined namespaces are not allowed. Only the default namespace 'defaultNs' is available.") + "User defined namespaces are not allowed. Only the default namespace 'johndoe-che' is available.") public void shouldThrowExceptionIfNonDefaultNamespaceIsSpecifiedAndUserDefinedAreNotAllowedOnCheckingIfNamespaceIsAllowed() throws Exception { + System.out.println("0--------"); + System.out.println(EnvironmentContext.getCurrent().getSubject()); + System.out.println("2--------"); projectFactory = new OpenShiftProjectFactory( - "legacy", "", null, - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -221,8 +200,12 @@ public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfName preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER); - - projectFactory.checkIfNamespaceIsAllowed("any-namespace"); + try { + projectFactory.checkIfNamespaceIsAllowed("any-namespace"); + } catch (ValidationException e) { + e.printStackTrace(); + throw e; + } } @Test( @@ -233,11 +216,9 @@ public void shouldNotThrowExceptionIfDefaultNamespaceIsSpecifiedOnCheckingIfName throws Exception { projectFactory = new OpenShiftProjectFactory( - "projectName", "", null, null, - false, true, true, NAMESPACE_LABELS, @@ -271,11 +252,9 @@ public void shouldReturnPreparedNamespacesWhenFound() throws InfrastructureExcep projectFactory = new OpenShiftProjectFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -306,15 +285,13 @@ public void shouldNotThrowAnExceptionWhenNotAllowedToListNamespaces() throws Exc doThrow(new KubernetesClientException("Not allowed.", 403, new Status())) .when(projectList) .getItems(); - prepareNamespaceToBeFoundByName("che-default", p); + prepareNamespaceToBeFoundByName("u123-che", p); projectFactory = new OpenShiftProjectFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -327,7 +304,7 @@ public void shouldNotThrowAnExceptionWhenNotAllowedToListNamespaces() throws Exc preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER); - EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false)); + EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "u123", null, false)); // when List availableNamespaces = projectFactory.list(); @@ -345,11 +322,9 @@ public void throwAnExceptionWhenErrorListingNamespaces() throws Exception { projectFactory = new OpenShiftProjectFactory( - "predefined", "", "", - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -372,10 +347,10 @@ public void throwAnExceptionWhenErrorListingNamespaces() throws Exception { @Test public void shouldReturnDefaultProjectWhenItExistsAndUserDefinedIsNotAllowed() throws Exception { prepareNamespaceToBeFoundByName( - "che-default", + USER_NAME + "-che", new ProjectBuilder() .withNewMetadata() - .withName("che-default") + .withName(USER_NAME + "-che") .withAnnotations( ImmutableMap.of( PROJECT_DISPLAY_NAME_ANNOTATION, @@ -390,11 +365,9 @@ public void shouldReturnDefaultProjectWhenItExistsAndUserDefinedIsNotAllowed() t projectFactory = new OpenShiftProjectFactory( - "predefined", "", null, - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -411,7 +384,7 @@ public void shouldReturnDefaultProjectWhenItExistsAndUserDefinedIsNotAllowed() t List availableNamespaces = projectFactory.list(); assertEquals(availableNamespaces.size(), 1); KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0); - assertEquals(defaultNamespace.getName(), "che-default"); + assertEquals(defaultNamespace.getName(), USER_NAME + "-che"); assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); assertEquals( defaultNamespace.getAttributes().get(PROJECT_DISPLAY_NAME_ATTRIBUTE), @@ -425,15 +398,13 @@ public void shouldReturnDefaultProjectWhenItExistsAndUserDefinedIsNotAllowed() t public void shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllowed() throws Exception { throwOnTryToGetProjectByName( - "che-default", new KubernetesClientException("forbidden", 403, null)); + USER_NAME + "-che", new KubernetesClientException("forbidden", 403, null)); projectFactory = new OpenShiftProjectFactory( - "predefined", "", null, - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -450,7 +421,7 @@ public void shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllow List availableNamespaces = projectFactory.list(); assertEquals(availableNamespaces.size(), 1); KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0); - assertEquals(defaultNamespace.getName(), "che-default"); + assertEquals(defaultNamespace.getName(), USER_NAME + "-che"); assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); assertNull( defaultNamespace @@ -461,18 +432,16 @@ public void shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllow @Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = - "Error while trying to fetch the project 'che-default'. Cause: connection refused") + "Error while trying to fetch the project 'johndoe-che'. Cause: connection refused") public void shouldThrowExceptionWhenFailedToGetInfoAboutDefaultNamespace() throws Exception { throwOnTryToGetProjectByName( - "che-default", new KubernetesClientException("connection refused")); + USER_NAME + "-che", new KubernetesClientException("connection refused")); projectFactory = new OpenShiftProjectFactory( - "predefined", "", null, - "che-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -489,97 +458,6 @@ public void shouldThrowExceptionWhenFailedToGetInfoAboutDefaultNamespace() throw projectFactory.list(); } - @Test - public void shouldReturnListOfExistingProjectsAlongWithDefaultIfUserDefinedIsAllowed() - throws Exception { - prepareListedProjects( - Arrays.asList( - createProject("my-for-ws", "Project for Workspaces", "some description", "Active"), - createProject("default", "Default Che Project", "some description", "Active"))); - - projectFactory = - new OpenShiftProjectFactory( - "predefined", - "", - null, - "default", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - configFactory, - stopWorkspaceRoleProvisioner, - userManager, - preferenceManager, - pool, - NO_OAUTH_IDENTITY_PROVIDER); - - List availableNamespaces = projectFactory.list(); - - assertEquals(availableNamespaces.size(), 2); - KubernetesNamespaceMeta forWS = availableNamespaces.get(0); - assertEquals(forWS.getName(), "my-for-ws"); - assertEquals( - forWS.getAttributes().get(PROJECT_DISPLAY_NAME_ATTRIBUTE), "Project for Workspaces"); - assertEquals(forWS.getAttributes().get(PROJECT_DESCRIPTION_ATTRIBUTE), "some description"); - assertEquals(forWS.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertNull(forWS.getAttributes().get(DEFAULT_ATTRIBUTE)); - - KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(1); - assertEquals(defaultNamespace.getName(), "default"); - assertEquals( - defaultNamespace.getAttributes().get(PROJECT_DISPLAY_NAME_ATTRIBUTE), - "Default Che Project"); - assertEquals( - defaultNamespace.getAttributes().get(PROJECT_DESCRIPTION_ATTRIBUTE), "some description"); - assertEquals(defaultNamespace.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); - } - - @Test - public void shouldReturnListOfExistingProjectsAlongWithNonExistingDefaultIfUserDefinedIsAllowed() - throws Exception { - prepareListedProjects(singletonList(createProject("my-for-ws", "", "", "Active"))); - - projectFactory = - new OpenShiftProjectFactory( - "predefined", - "", - null, - "default", - true, - true, - true, - NAMESPACE_LABELS, - NAMESPACE_ANNOTATIONS, - clientFactory, - cheClientFactory, - configFactory, - stopWorkspaceRoleProvisioner, - userManager, - preferenceManager, - pool, - NO_OAUTH_IDENTITY_PROVIDER); - - List availableNamespaces = projectFactory.list(); - assertEquals(availableNamespaces.size(), 2); - KubernetesNamespaceMeta forWS = availableNamespaces.get(0); - assertEquals(forWS.getName(), "my-for-ws"); - assertEquals(forWS.getAttributes().get(PHASE_ATTRIBUTE), "Active"); - assertNull(forWS.getAttributes().get(DEFAULT_ATTRIBUTE)); - - KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(1); - assertEquals(defaultNamespace.getName(), "default"); - assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true"); - assertNull( - defaultNamespace - .getAttributes() - .get(PHASE_ATTRIBUTE)); // no phase - means such namespace does not exist - } - @Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = @@ -588,11 +466,9 @@ public void shouldThrowExceptionWhenFailedToGetNamespaces() throws Exception { throwOnTryToGetProjectsList(new KubernetesClientException("connection refused")); projectFactory = new OpenShiftProjectFactory( - "predefined", "", null, - "default-ns", - true, + "-che", true, true, NAMESPACE_LABELS, @@ -622,11 +498,9 @@ public void shouldRequireNamespacePriorExistenceIfDifferentFromDefaultAndUserDef projectFactory = spy( new OpenShiftProjectFactory( - "predefined", "", null, - "new-default", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -660,11 +534,9 @@ public void shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndProjectIsNotP projectFactory = spy( new OpenShiftProjectFactory( - "", "serviceAccount", null, - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -700,11 +572,9 @@ public void shouldCallStopWorkspaceRoleProvisionWhenIdentityProviderIsDefined() projectFactory = spy( new OpenShiftProjectFactory( - "", "serviceAccount", null, - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -742,11 +612,9 @@ public void shouldNotCallStopWorkspaceRoleProvisionWhenIdentityProviderIsDefined projectFactory = spy( new OpenShiftProjectFactory( - "", "serviceAccount", null, - "", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -796,11 +664,9 @@ public void testEvalNamespaceNameWhenPreparedNamespacesFound() throws Infrastruc projectFactory = new OpenShiftProjectFactory( - "legacy", "", "", - "defaultNs", - false, + "-che", true, true, NAMESPACE_LABELS, @@ -831,11 +697,9 @@ public void testUsernamePlaceholderInLabelsIsNotEvaluated() throws Infrastructur projectFactory = new OpenShiftProjectFactory( - "predefined", "", null, - "che-default", - false, + "-che", true, true, "try_placeholder_here=", @@ -880,7 +744,7 @@ private void prepareListedProjects(List projects) throws Exception { } private void throwOnTryToGetProjectsList(Throwable e) throws Exception { - when(projectOperation.list()).thenThrow(e); + when(projectListResource.list()).thenThrow(e); } private Project createProject(String name, String displayName, String description, String phase) { diff --git a/multiuser/permission/che-multiuser-permission-workspace/src/main/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilter.java b/multiuser/permission/che-multiuser-permission-workspace/src/main/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilter.java index 825d8efaa06..f530ffdc9c2 100644 --- a/multiuser/permission/che-multiuser-permission-workspace/src/main/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilter.java +++ b/multiuser/permission/che-multiuser-permission-workspace/src/main/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilter.java @@ -97,7 +97,7 @@ public void filter(GenericResourceMethod genericResourceMethod, Object[] argumen case "create": { - checkAccountPermissions((String) arguments[4], AccountOperation.CREATE_WORKSPACE); + checkAccountPermissions((String) arguments[3], AccountOperation.CREATE_WORKSPACE); return; } diff --git a/multiuser/permission/che-multiuser-permission-workspace/src/test/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilterTest.java b/multiuser/permission/che-multiuser-permission-workspace/src/test/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilterTest.java index 570c61ad307..b822452ea84 100644 --- a/multiuser/permission/che-multiuser-permission-workspace/src/test/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilterTest.java +++ b/multiuser/permission/che-multiuser-permission-workspace/src/test/java/org/eclipse/che/multiuser/permission/workspace/server/filters/WorkspacePermissionsFilterTest.java @@ -137,8 +137,7 @@ public void shouldCheckAccountPermissionsAccessOnWorkspaceCreationFromDevfile() .post(SECURE_PATH + "/workspace/devfile?namespace=userok"); assertEquals(response.getStatusCode(), 204); - verify(workspaceService) - .create(any(DevfileDto.class), any(), any(), any(), eq("userok"), any()); + verify(workspaceService).create(any(DevfileDto.class), any(), any(), eq("userok"), any()); verify(permissionsFilter).checkAccountPermissions("userok", AccountOperation.CREATE_WORKSPACE); verifyZeroInteractions(subject); } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java index 26221ce882b..32cce44630d 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceManager.java @@ -492,8 +492,7 @@ private void startAsync( workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE); if (isNullOrEmpty(targetNamespace)) { try { - targetNamespace = - runtimes.evalLegacyInfrastructureNamespace(buildResolutionContext(workspace)); + targetNamespace = runtimes.evalInfrastructureNamespace(buildResolutionContext(workspace)); workspace .getAttributes() .put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, targetNamespace); diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java index b3c3a22a124..9d5e7a66d30 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java @@ -282,11 +282,6 @@ public String evalInfrastructureNamespace(NamespaceResolutionContext resolutionC return infrastructure.evaluateInfraNamespace(resolutionCtx); } - public String evalLegacyInfrastructureNamespace(NamespaceResolutionContext resolutionContext) - throws InfrastructureException { - return infrastructure.evaluateLegacyInfraNamespace(resolutionContext); - } - /** * This method just passes on the question down to the underlying infrastructure. * diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java index 6d4d9989884..12fb213e81d 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java @@ -30,7 +30,6 @@ import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_STORAGE_PREFERRED_TYPE; import static org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START; import static org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES; -import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; @@ -188,14 +187,6 @@ public Response create( examples = @Example({@ExampleProperty("attrName:value-with:colon")})) @QueryParam("attribute") List attrsList, - @ApiParam( - value = - "The target infrastructure namespace (Kubernetes namespace or OpenShift" - + " project) where the workspace should be deployed to when started. This" - + " parameter is optional. The workspace creation will fail if the Che server" - + " is configured to not allow deploying into that infrastructure namespace.") - @QueryParam("infrastructure-namespace") - String infrastructureNamespace, @ApiParam( "If true then the workspace will be immediately " + "started after it is successfully created") @@ -212,9 +203,6 @@ public Response create( if (namespace == null) { namespace = EnvironmentContext.getCurrent().getSubject().getUserName(); } - if (!isNullOrEmpty(infrastructureNamespace)) { - attributes.put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, infrastructureNamespace); - } WorkspaceImpl workspace; try { workspace = diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/RuntimeInfrastructure.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/RuntimeInfrastructure.java index 1378d228f1c..79052562d5a 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/RuntimeInfrastructure.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/RuntimeInfrastructure.java @@ -122,20 +122,6 @@ public RuntimeContext prepare(RuntimeIdentity identity, InternalEnvironment envi public abstract String evaluateInfraNamespace(NamespaceResolutionContext resolutionCtx) throws InfrastructureException; - /** - * Returns the namespace a workspace should be deployed into when using the legacy (pre 7.5.0) - * logic. This is required to handle a case where we're starting a workspace created using an old - * version of the Che server that didn't store the infrastructure namespace in the workspace - * attributes. - * - * @param resolutionContext the runtime holder specifying which user and workspace runtime - * targets. - * @throws InfrastructureException when there is no configured default namespace or any other - * error - */ - public abstract String evaluateLegacyInfraNamespace(NamespaceResolutionContext resolutionContext) - throws InfrastructureException; - /** * Checks whether the infrastructure namespace is valid in this infrastructure. * diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java index 21cdb853b7b..6d8959e427c 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceManagerTest.java @@ -598,7 +598,7 @@ public void evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart() throws Exce DevfileImpl devfile = mock(DevfileImpl.class); WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, new HashMap<>()); workspace.getAttributes().remove(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE); - when(runtimes.evalLegacyInfrastructureNamespace(any())).thenReturn("evaluated-legacy"); + when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legacy"); EnvironmentImpl environment = new EnvironmentImpl(null, emptyMap()); Command command = new CommandImpl("cmd", "echo hello", "custom"); @@ -627,7 +627,7 @@ public void evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart() throws Exce .get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legacy"); verify(runtimes) - .evalLegacyInfrastructureNamespace( + .evalInfrastructureNamespace( new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1)); } @@ -708,7 +708,7 @@ public void doNotEvaluateInfraNamespaceIfItIsSpecifiedOnWorkspaceStart() throws .getAttributes() .get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "user-defined"); - verify(runtimes, never()).evalLegacyInfrastructureNamespace(any()); + verify(runtimes, never()).evalInfrastructureNamespace(any()); } @Test diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java index 4977ba0df3e..607d64fccd6 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimesTest.java @@ -1059,12 +1059,6 @@ public String evaluateInfraNamespace(NamespaceResolutionContext ctx) { return "defaultNamespace"; } - @Override - public String evaluateLegacyInfraNamespace(NamespaceResolutionContext resolutionContext) - throws InfrastructureException { - return "defaultLegacyNamespace"; - } - @Override public boolean isNamespaceValid(String namespaceName) { return true; diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java index d5c2dbe17ca..3ec86f08eb8 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java @@ -228,47 +228,6 @@ public void shouldCreateWorkspaceFromDevfile() throws Exception { any()); } - @Test - public void shouldCreateWorkspaceFromDevfileInNamespace() throws Exception { - final DevfileDto devfileDto = createDevfileDto(); - final WorkspaceImpl workspace = createWorkspace(devfileDto); - - when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())) - .thenReturn(workspace); - - final Response response = - given() - .auth() - .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) - .contentType("application/json") - .body(devfileDto) - .when() - .post( - SECURE_PATH - + "/workspace/devfile" - + "?namespace=test" - + "&attribute=factoryId:factory123" - + "&attribute=custom:custom:value" - + "&infrastructure-namespace=my-namespace"); - - assertEquals(response.getStatusCode(), 201); - assertEquals( - new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace); - verify(wsManager) - .createWorkspace( - any(Devfile.class), - eq("test"), - eq( - ImmutableMap.of( - "factoryId", - "factory123", - "custom", - "custom:value", - "infrastructureNamespace", - "my-namespace")), - any()); - } - @Test public void shouldReturnBadRequestOnInvalidDevfile() throws Exception { final DevfileDto devfileDto = createDevfileDto();