Skip to content

Commit

Permalink
Propagate default value for persistVolumes for clients
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Leshchenko <[email protected]>
  • Loading branch information
sleshchenko committed Jan 23, 2020
1 parent e8ab082 commit e8d92d6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ che.workspace.plugin_registry_url=https://che-plugin-registry.prod-preview.opens
# In case Che plugins tooling is not needed value 'NULL' should be used
che.workspace.devfile_registry_url=https://che-devfile-registry.prod-preview.openshift.io/

# Defines a default value for persist volumes that clients like Dashboard
# should propose for users during workspace creation.
# Possible values: true or false
# In case of true - PersistentVolumeClaims are used by declared volumes by user and plugins. `true`
# value is supposed not to be set explicitly in Devfile attributes since it's default fixed behaviour.
# In case of false - emptyDir is used instead of PVCs. Note that data will be lost after workspace restart.
che.workspace.persist_volumes.default=true

# Configures in which way secure servers will be protected with authentication.
# Suitable values:
# - 'default': no additionally authentication system will be enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public final class Constants {

public static final String CHE_WORKSPACE_AUTO_START = "che.workspace.auto_start";

/**
* The configuration property that defines a default value for persist volumes that clients like
* Dashboard should propose for users during workspace creation.
*
* <p>Possible values: true or false
*
* <ul>
* <li>In case of true - PersistentVolumeClaims are used by declared volumes by user and
* plugins. `true` value is supposed not to be set explicitly in Devfile attributes since
* it's default fixed behaviour.
* <li>In case of false - emptyDir is used instead of PVCs. Note that data will be lost after
* workspace restart.
* </ul>
*/
public static final String CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY =
"che.workspace.persist_volumes.default";

/** Property name for Che plugin registry url. */
public static final String CHE_WORKSPACE_PLUGIN_REGISTRY_URL_PROPERTY =
"che.workspace.plugin_registry_url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.eclipse.che.api.workspace.server.WorkspaceKeyValidator.validateKey;
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START;
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_DEVFILE_REGISTRY_URL_PROPERTY;
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY;
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_PLUGIN_REGISTRY_URL_PROPERTY;
import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE;

Expand Down Expand Up @@ -107,6 +108,7 @@ public class WorkspaceService extends Service {
private final String apiEndpoint;
private final boolean cheWorkspaceAutoStart;
private final FileContentProvider devfileContentProvider;
private final boolean defaultPersistVolumes;

@Inject
public WorkspaceService(
Expand All @@ -117,6 +119,7 @@ public WorkspaceService(
WorkspaceLinksGenerator linksGenerator,
@Named(CHE_WORKSPACE_PLUGIN_REGISTRY_URL_PROPERTY) @Nullable String pluginRegistryUrl,
@Named(CHE_WORKSPACE_DEVFILE_REGISTRY_URL_PROPERTY) @Nullable String devfileRegistryUrl,
@Named(CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY) boolean defaultPersistVolumes,
URLFetcher urlFetcher) {
this.apiEndpoint = apiEndpoint;
this.cheWorkspaceAutoStart = cheWorkspaceAutoStart;
Expand All @@ -126,6 +129,7 @@ public WorkspaceService(
this.pluginRegistryUrl = pluginRegistryUrl;
this.devfileRegistryUrl = devfileRegistryUrl;
this.devfileContentProvider = new URLFileContentProvider(null, urlFetcher);
this.defaultPersistVolumes = defaultPersistVolumes;
}

@POST
Expand Down Expand Up @@ -829,6 +833,8 @@ public Map<String, String> getSettings() {
settings.put("cheWorkspaceDevfileRegistryUrl", devfileRegistryUrl);
}

settings.put(CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY, Boolean.toString(defaultPersistVolumes));

return settings.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.eclipse.che.api.core.model.workspace.config.MachineConfig.MEMORY_LIMIT_ATTRIBUTE;
import static org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.RUNNING;
import static org.eclipse.che.api.workspace.server.DtoConverter.asDto;
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY;
import static org.eclipse.che.dto.server.DtoFactory.newDto;
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME;
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_PASSWORD;
Expand Down Expand Up @@ -123,6 +124,8 @@ public class WorkspaceServiceTest {
private static final String CHE_WORKSPACE_PLUGIN_REGISTRY_ULR = "http://localhost:9898/plugins/";
private static final String CHE_WORKSPACE_DEVFILE_REGISTRY_ULR =
"http://localhost:9898/devfiles/";
private static final boolean CHE_WORKSPACES_DEFAULT_PERSIST_VOLUMES = false;

private static final Account TEST_ACCOUNT = new AccountImpl("anyId", NAMESPACE, "test");

@SuppressWarnings("unused")
Expand All @@ -149,6 +152,7 @@ public void setup() {
linksGenerator,
CHE_WORKSPACE_PLUGIN_REGISTRY_ULR,
CHE_WORKSPACE_DEVFILE_REGISTRY_ULR,
CHE_WORKSPACES_DEFAULT_PERSIST_VOLUMES,
urlFetcher);
}

Expand Down Expand Up @@ -1327,7 +1331,9 @@ public void shouldBeAbleToGetSettings() throws Exception {
"cheWorkspacePluginRegistryUrl",
CHE_WORKSPACE_PLUGIN_REGISTRY_ULR,
"cheWorkspaceDevfileRegistryUrl",
CHE_WORKSPACE_DEVFILE_REGISTRY_ULR));
CHE_WORKSPACE_DEVFILE_REGISTRY_ULR,
CHE_WORKSPACE_PERSIST_VOLUMES_PROPERTY,
Boolean.toString(CHE_WORKSPACES_DEFAULT_PERSIST_VOLUMES)));
}

private static String unwrapError(Response response) {
Expand Down

0 comments on commit e8d92d6

Please sign in to comment.