Skip to content

Commit 37f73bb

Browse files
committed
Fix API workspace SCC selection for container run mode
Signed-off-by: SkorikSergey <sskoryk@redhat.com>
1 parent 6cff55e commit 37f73bb

4 files changed

Lines changed: 43 additions & 13 deletions

File tree

‎tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ void (async function (): Promise<void> {
4949
const devfilesBuildCommands: any[] = [];
5050

5151
test('Get DevWorkspace configuration', async function (): Promise<void> {
52+
kubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor);
53+
kubernetesCommandLineToolsExecutor.loginToOcp();
5254
devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
5355
devfileUrl: devfileSample.link
5456
});
5557
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
5658
devWorkspaceName = devfileContext?.devWorkspace?.metadata?.name;
57-
kubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor);
5859
kubernetesCommandLineToolsExecutor.workspaceName = devWorkspaceName;
5960
containerTerminal = e2eContainer.get(CLASSES.ContainerTerminal);
60-
kubernetesCommandLineToolsExecutor.loginToOcp();
6161
});
6262

6363
test('Collect build commands from the devfile', function (): void {

‎tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ suite('Empty workspace API test', function (): void {
3232
const gitRepository: string = 'https://github.com/crw-qe/web-nodejs-sample';
3333

3434
suiteSetup(`Create empty workspace with OC client ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise<void> {
35+
kubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor);
36+
kubernetesCommandLineToolsExecutor.loginToOcp();
3537
const workspaceName: string = 'empty-' + Math.floor(Math.random() * 1000);
3638
const devfileContent: string = 'schemaVersion: 2.2.0\n' + 'metadata:\n' + ` name: ${workspaceName}\n`;
3739
const editorContent: string = '';
@@ -42,14 +44,12 @@ suite('Empty workspace API test', function (): void {
4244
});
4345
devfileContext = await devWorkspaceConfigurationHelper.generateDevfileContext();
4446
devWorkspaceName = devfileContext?.devWorkspace?.metadata?.name;
45-
kubernetesCommandLineToolsExecutor = e2eContainer.get(CLASSES.KubernetesCommandLineToolsExecutor);
4647
kubernetesCommandLineToolsExecutor.workspaceName = devWorkspaceName;
4748
kubernetesCommandLineToolsExecutor.namespace = namespace;
4849
containerTerminal = e2eContainer.get(CLASSES.ContainerTerminal);
4950
});
5051

5152
test('Create empty workspace', function (): void {
52-
kubernetesCommandLineToolsExecutor.loginToOcp();
5353
const devWorkspaceConfigurationYamlString: string =
5454
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
5555
const output: ShellString = kubernetesCommandLineToolsExecutor.applyAndWaitDevWorkspace(devWorkspaceConfigurationYamlString);

‎tests/e2e/specs/miscellaneous/PredefinedNamespace.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ suite(`Create predefined workspace and check it ${BASE_TEST_CONSTANTS.TEST_ENVIR
5959
// generate empty workspace DevFile and create it through oc client under a regular user
6060
suiteSetup('Login', async function (): Promise<void> {
6161
const devfileContent: string = 'schemaVersion: 2.2.0\n' + 'metadata:\n' + ` name: ${workspaceName}\n`;
62-
kubernetesCommandLineToolsExecutor.loginToOcp(userName);
6362
devWorkspaceConfigurationHelper = new DevWorkspaceConfigurationHelper({
6463
devfileContent
6564
});
@@ -88,6 +87,8 @@ suite(`Create predefined workspace and check it ${BASE_TEST_CONSTANTS.TEST_ENVIR
8887

8988
const devWorkspaceConfigurationYamlString: string =
9089
devWorkspaceConfigurationHelper.getDevWorkspaceConfigurationYamlAsString(devfileContext);
90+
// read installation settings as admin, then create the workspace as the regular user.
91+
kubernetesCommandLineToolsExecutor.loginToOcp(userName);
9192
kubernetesCommandLineToolsExecutor.applyWithoutNamespace(devWorkspaceConfigurationYamlString);
9293
});
9394

‎tests/e2e/utils/DevWorkspaceConfigurationHelper.ts‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,48 @@ export class DevWorkspaceConfigurationHelper {
108108
}
109109

110110
/**
111-
* add missed attributes to fix issues CRW-8922, CRW-9187.
111+
* add Dev Spaces attributes and match the SCC to the configured container capabilities.
112112
*/
113113
addMissedDevWorkspaceConfigAttributes(
114114
devfileContextDevWorkspace: DevfileContext,
115115
storageType: string | undefined = API_TEST_CONSTANTS.TS_API_TEST_STORAGE_TYPE
116116
): void {
117117
Logger.debug();
118-
devfileContextDevWorkspace.devWorkspace?.spec?.template &&
119-
(devfileContextDevWorkspace.devWorkspace.spec.template.attributes = YAML.parse(`
120-
controller.devfile.io/devworkspace-config:
121-
name: devworkspace-config
122-
namespace: openshift-devspaces
123-
controller.devfile.io/scc: container-build
124-
controller.devfile.io/storage-type: ${storageType}`));
118+
const template: V1alpha2DevWorkspaceTemplate['spec'] = devfileContextDevWorkspace.devWorkspace?.spec?.template;
119+
if (!template) {
120+
return;
121+
}
122+
123+
const devSpacesNamespace: string = 'openshift-devspaces';
124+
const devEnvironments: {
125+
disableContainerRunCapabilities?: boolean;
126+
disableContainerBuildCapabilities?: boolean;
127+
containerRunConfiguration?: { openShiftSecurityContextConstraint?: string };
128+
containerBuildConfiguration?: { openShiftSecurityContextConstraint?: string };
129+
} = JSON.parse(
130+
this.shellExecutor.executeArbitraryShellScript(
131+
`oc get checluster -n ${devSpacesNamespace} -o jsonpath='{.items[0].spec.devEnvironments}'`
132+
)
133+
);
134+
135+
template.attributes = {
136+
...template.attributes,
137+
'controller.devfile.io/devworkspace-config': {
138+
name: 'devworkspace-config',
139+
namespace: devSpacesNamespace
140+
},
141+
'controller.devfile.io/storage-type': storageType
142+
};
143+
144+
// container run takes precedence when both run and build capabilities are enabled.
145+
if (devEnvironments.disableContainerRunCapabilities === false) {
146+
template.attributes['controller.devfile.io/scc'] =
147+
devEnvironments.containerRunConfiguration?.openShiftSecurityContextConstraint || 'container-run';
148+
} else if (devEnvironments.disableContainerBuildCapabilities !== true) {
149+
template.attributes['controller.devfile.io/scc'] =
150+
devEnvironments.containerBuildConfiguration?.openShiftSecurityContextConstraint || 'container-build';
151+
} else {
152+
delete template.attributes['controller.devfile.io/scc'];
153+
}
125154
}
126155
}

0 commit comments

Comments
 (0)