Skip to content

Commit

Permalink
Get devfile yaml from file; add -t to oc exec command
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Nochevnov <[email protected]>
  • Loading branch information
dmytro-ndp committed Jan 8, 2025
1 parent 63c4709 commit 6f7778e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { OAUTH_CONSTANTS } from '../constants/OAUTH_CONSTANTS';
import { IKubernetesCommandLineToolsExecutor } from './IKubernetesCommandLineToolsExecutor';
import { inject, injectable } from 'inversify';
import { CLASSES } from '../configs/inversify.types';
import * as fs from 'fs';

@injectable()
export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLineToolsExecutor {
Expand Down Expand Up @@ -128,15 +129,20 @@ export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLin
Logger.debug(`${this.kubernetesCommandLineTool}`);

return this.shellExecutor.executeCommand(
`${this.kubernetesCommandLineTool} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`
`${this.kubernetesCommandLineTool} exec -i -t ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium test

This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
This string concatenation which depends on
library input
is later used in a
shell command
.
);
}

applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
Logger.debug(`${this.kubernetesCommandLineTool}`);

// write yaml configuration to the devfile file
const randomSuffix: number = Math.floor(Math.random() * 10000);
const devfileYamlPath: string = `/tmp/devfile-${randomSuffix}.yaml`;
fs.writeFileSync(devfileYamlPath, yamlConfiguration);

return this.shellExecutor.executeCommand(
`cat <<EOF | ${this.kubernetesCommandLineTool} apply -n ${this.namespace} -f - \n` + yamlConfiguration + '\n' + 'EOF'
`${this.kubernetesCommandLineTool} apply -n ${this.namespace} -f ${devfileYamlPath} && rm -f ${devfileYamlPath}`
);
}

Expand Down

0 comments on commit 6f7778e

Please sign in to comment.