Skip to content

Commit

Permalink
Pod and container overrides via attribute API tests (#22195)
Browse files Browse the repository at this point in the history
* Pod and container overrides via attribute API tests
---------

Signed-off-by: mdolhalo <mdolhalo@redhat.com>
Co-authored-by: Maryna Dolhalova <mdolhalo@redhat.com>
  • Loading branch information
nallikaea and Maryna Dolhalova committed May 3, 2023
1 parent 2c79499 commit 03ef436
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 1,972 deletions.
1,980 changes: 11 additions & 1,969 deletions tests/e2e/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "3.9.9",
"vscode-extension-tester-locators": "3.1.0"
"vscode-extension-tester-locators": "3.1.0",
"yaml": "^2.2.2"
},
"dependencies": {
"@eclipse-che/api": "latest",
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/resources/container-overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
name: web-terminal-container-overrides
spec:
started: true
template:
attributes:
controller.devfile.io/storage-type: ephemeral
projects:
- name: web-nodejs-sample
git:
remotes:
origin: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- name: web-terminal
attributes:
container-overrides: {"resources":{"limits":{"nvidia.com/gpu":"1"}}}
container:
image: quay.io/wto/web-terminal-tooling:next
args:
- tail
- '-f'
- /dev/null
cpuLimit: 400m
cpuRequest: 100m
memoryLimit: 256Mi
memoryRequest: 128Mi
37 changes: 37 additions & 0 deletions tests/e2e/resources/pod-overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
name: code-latest-pod-overrides
spec:
started: true
template:
attributes:
pod-overrides:
metadata:
annotations:
io.openshift.userns: "true"
io.kubernetes.cri-o.userns-mode: "auto:size=65536;map-to-root=true" # <-- user namespace
openshift.io/scc: container-build
spec:
runtimeClassName: kata
schedulerName: stork
projects:
- name: web-nodejs-sample
git:
remotes:
origin: "https://github.com/che-samples/web-nodejs-sample.git"
commands:
- id: say-hello
exec:
component: che-code-runtime-description
commandLine: echo "Hello from $(pwd)"
workingDir: ${PROJECT_SOURCE}/app
contributions:
- name: che-code
uri: https://eclipse-che.github.io/che-plugin-registry/main/v3/plugins/che-incubator/che-code/latest/devfile.yaml
components:
- name: che-code-runtime-description
container:
env:
- name: CODE_HOST
value: 0.0.0.0
37 changes: 37 additions & 0 deletions tests/e2e/specs/api/ContainerOverridesAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import fs from 'fs';
import path from 'path';
import YAML from 'yaml';
import { expect } from 'chai';

suite(`Test defining container overrides via attribute.`, async function (): Promise<void> {
const pathToSampleFile: string = path.resolve('resources/container-overrides.yaml');
const workspaceName: string = YAML.parse(fs.readFileSync(pathToSampleFile, 'utf8')).metadata.name;
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = new KubernetesCommandLineToolsExecutor(workspaceName);

suiteSetup('Login into OC client', function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
});

suiteTeardown('Delete DewWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace();
});

test('Apply container-overrides sample as DewWorkspace with OC client', function (): void {
kubernetesCommandLineToolsExecutor.applyYamlConfigurationAsFile(pathToSampleFile);
kubernetesCommandLineToolsExecutor.wait(5);
});

test('Check that fields are overridden in the Deployment for DewWorkspace', function (): void {
const devWorkspaceFullYamlOutput: Object = YAML.parse(kubernetesCommandLineToolsExecutor.getDevWorkspaceYamlConfiguration());
expect(devWorkspaceFullYamlOutput.spec.template.components[0].attributes['container-overrides']).eqls({
resources: {
limits: {
'nvidia.com/gpu': '1'
}
}
});
});
});


43 changes: 43 additions & 0 deletions tests/e2e/specs/api/PodOverridesAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import fs from 'fs';
import path from 'path';
import YAML from 'yaml';
import { expect } from 'chai';

suite(`Test defining pod overrides via attribute.`, async function (): Promise<void> {
const pathToSampleFile: string = path.resolve('resources/pod-overrides.yaml');
const workspaceName: string = YAML.parse(fs.readFileSync(pathToSampleFile, 'utf8')).metadata.name;
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = new KubernetesCommandLineToolsExecutor(workspaceName);

suiteSetup('Login into OC client', function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp();
});

suiteTeardown('Delete DewWorkspace', function (): void {
kubernetesCommandLineToolsExecutor.deleteDevWorkspace();
});

test('Apply pod-overrides sample as DewWorkspace with OC client', function (): void {
kubernetesCommandLineToolsExecutor.applyYamlConfigurationAsFile(pathToSampleFile);
kubernetesCommandLineToolsExecutor.wait(5);
});

test('Check that fields are overridden in the Deployment for DewWorkspace', function (): void {
const devWorkspaceFullYamlOutput: Object = YAML.parse(kubernetesCommandLineToolsExecutor.getDevWorkspaceYamlConfiguration());
expect(devWorkspaceFullYamlOutput.spec.template.attributes['pod-overrides']).eqls({
metadata: {
annotations: {
'io.kubernetes.cri-o.userns-mode': 'auto:size=65536;map-to-root=true',
'io.openshift.userns': 'true',
'openshift.io/scc': 'container-build'
}
},
spec: {
runtimeClassName: 'kata',
schedulerName: 'stork'
}
});
});
});


3 changes: 3 additions & 0 deletions tests/e2e/tests-library/ProjectAndFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class ProjectAndFileTests {

public async waitWorkspaceReadinessForCheCodeEditor(): Promise<void> {
try {
const start: number = new Date().getTime();
await this.driverHelper.getDriver().wait(until.elementLocated(By.className('monaco-workbench')), TimeoutConstants.TS_SELENIUM_START_WORKSPACE_TIMEOUT);
const end: number = new Date().getTime();
Logger.debug(`${this.constructor.name}.${this.waitWorkspaceReadinessForCheCodeEditor.name} - editor was opened in ${end - start} seconds.`);
} catch (err) {
Logger.error(`ProjectAndFileTestsCheCode.waitWorkspaceReadinessForCheCodeEditor - waiting for workspace readiness failed: ${err}`);
throw err;
Expand Down
14 changes: 12 additions & 2 deletions tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { echo, exec, ShellString } from 'shelljs';
import { KubernetesCommandLineTool, TestConstants } from '../constants/TestConstants';
import { Logger } from './Logger';
import { ShellExecutor } from './ShellExecutor';
import { TimeoutConstants } from '../constants/TimeoutConstants';
import * as path from 'path';

export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
private static container: string;
Expand Down Expand Up @@ -84,6 +84,16 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
'EOF');
}

applyYamlConfigurationAsFile(pathToFile: string): void {
Logger.debug(`${this.getLoggingName(this.applyYamlConfigurationAsFile.name)}:`);
this.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f "${path.resolve(pathToFile)}"`);
}

getDevWorkspaceYamlConfiguration(): ShellString {
Logger.debug(`${this.getLoggingName(this.getDevWorkspaceYamlConfiguration.name)}:`);
return this.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get dw ${this.workspaceName} -n ${this.namespace} -o yaml`);
}

waitDevWorkspace(timeout: number = 360): ShellString {
Logger.debug(`${this.getLoggingName(this.waitDevWorkspace.name)}: Wait till workspace ready.`);
return this.execWithLog(`${(this.KUBERNETES_COMMAND_LINE_TOOL)} wait -n ${this.namespace} --for=condition=Ready dw ${this.workspaceName} --timeout=${timeout}s`);
Expand All @@ -94,7 +104,7 @@ export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
this.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} create namespace ${this.namespace}`);
}

createProject(projectName: string, timeout: number = TimeoutConstants.TS_SELENIUM_TERMINAL_DEFAULT_TIMEOUT * 2): void {
createProject(projectName: string): void {
Logger.debug(`${this.getLoggingName(this.createProject.name)}: Create new project "${projectName}".`);
this.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} new-project ${projectName} -n ${this.namespace}`);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/utils/ShellExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { echo, exec, ShellString } from 'shelljs';

export class ShellExecutor {

wait(seconds: number): void {
this.execWithLog(`sleep ${seconds}s`);
}

protected execWithLog(command: string): ShellString {
echo(command);
return exec(command);
Expand Down

0 comments on commit 03ef436

Please sign in to comment.