Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,12 @@
"type": "number",
"default": 9216,
"description": "MiB of memory to allocate to the OpenShift cluster as selected during the first run"
},
"openshiftConnector.crcNameserver": {
"Title": "CRC Domain Name Server",
"type": "string",
"default": "",
"description": "IP address/name of DNS to use with CRC"
}
}
}
Expand Down
47 changes: 37 additions & 10 deletions src/webview/cluster/app/clusterView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export default function addClusterView(props) {
const [statusError, setStatusError] = React.useState(false);

React.useEffect(() => {
props.vscode.postMessage({action: 'checksetting'});
props.vscode.postMessage({
action: 'checksetting'
});
}, []);

const steps = getSteps();
Expand Down Expand Up @@ -168,14 +170,18 @@ export default function addClusterView(props) {
setProgress(true);
setCrcStartError(false);
if (settingPresent) {
props.vscode.postMessage({action: 'crcStart', isSetting: true });
props.vscode.postMessage({
action: 'crcStart', isSetting: true
});
} else {
const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`:
`${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`;
const nameServerOpt = crcNameserver ? `-n ${crcNameserver}` : '';

props.vscode.postMessage({
action: 'crcStart',
data: crcStartCommand,
data: {
tool: fileName,
options: `start -p "${pullSecretPath}" -c ${cpuSize} -m ${memory} ${nameServerOpt} -o json`
},
pullSecret: pullSecretPath,
crcLoc: fileName,
cpuSize,
Expand Down Expand Up @@ -220,23 +226,44 @@ export default function addClusterView(props) {
const handleStopProcess = () => {
setStopProgress(true);
setCrcStopError(false);
props.vscode.postMessage({action: 'crcStop', data: `${fileName}`});
props.vscode.postMessage({
action: 'crcStop',
data: {
tool: fileName
}
});
}

const handleCrcSetup = () => {
props.vscode.postMessage({action: 'crcSetup', data: `${fileName}` })
props.vscode.postMessage({
action: 'crcSetup',
data: {
tool: fileName
}
})
}

const handleCrcLogin = (loginDetails, clusterUrl) => {
props.vscode.postMessage({action: 'crcLogin', data: loginDetails, url: clusterUrl })
props.vscode.postMessage({
action: 'crcLogin',
data: loginDetails,
url: clusterUrl
})
}

const handleRefresh = () => {
setStatusSkeleton(true);
if (settingPresent) {
props.vscode.postMessage({action: 'checksetting'});
props.vscode.postMessage({
action: 'checksetting'
});
} else {
props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
props.vscode.postMessage({
action: 'checkcrcstatus',
data: {
tool: fileName
}
});
}
}

Expand Down
68 changes: 40 additions & 28 deletions src/webview/cluster/clusterViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class ClusterViewLoader {
@vsCommand('openshift.explorer.addCluster.crcSetup')
static async crcSetup(event: any) {
const terminal: vscode.Terminal = WindowUtil.createTerminal('OpenShift: CRC Setup', undefined);
terminal.sendText(`${event.data} setup`);
terminal.sendText(`"${event.data.tool}" setup`);
terminal.show();
}

Expand All @@ -112,13 +112,15 @@ export default class ClusterViewLoader {
const pullSecretFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcPullSecretPath');
const cpuFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcCpuCores');
const memoryFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcMemoryAllocated');
const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, '-ojson'];
const nameserver = vscode.workspace.getConfiguration('openshiftConnector').get<string>('crcNameserver');
const nameserverOption = nameserver ? ['-n', nameserver] : [];
const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, ...nameserverOption, '-o json'];

startProcess = spawn(`${binaryFromSetting}`, crcOptions);
channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`);
channel.append(`\n\n"${binaryFromSetting}" ${crcOptions.join(' ')}\n`);
} else {
const [tool, ...params] = event.data.split(' ');
startProcess = spawn(tool, params);
channel.append(`\n\n${tool} ${params.join(' ')}\n`);
startProcess = spawn(`${event.data.tool}`, event.data.options.split(' '));
channel.append(`\n\n"${event.data.tool}" ${event.data.options}\n`);
}
startProcess.stdout.setEncoding('utf8');
startProcess.stderr.setEncoding('utf8');
Expand All @@ -137,32 +139,42 @@ export default class ClusterViewLoader {
const binaryLoc = event.isSetting ? vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'): event.crcLoc;
ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel);
});
startProcess.on('error', (err) => {
console.log(err);
});
}

@vsCommand('openshift.explorer.addCluster.crcStop')
static async crcStop(event) {
let filePath: string;
channel.show();
if (event.data === '') {
if (event.data.tool === '') {
filePath = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
} else {
filePath = event.data;
filePath = event.data.tool;
}
try {
const stopProcess = spawn(`${filePath}`, ['stop']);
channel.append(`\n\n"${filePath}" stop\n`);
stopProcess.stdout.setEncoding('utf8');
stopProcess.stderr.setEncoding('utf8');
stopProcess.stdout.on('data', (chunk) => {
channel.append(chunk);
});
stopProcess.stderr.on('data', (chunk) => {
channel.append(chunk);
});
stopProcess.on('close', (code) => {
// eslint-disable-next-line no-console
console.log(`crc stop exited with code ${code}`);
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
});
stopProcess.on('error', (err) => {
console.log(err);
});
} catch(err) {
console.log(err);
}
const stopProcess = spawn(`${filePath}`, ['stop']);
channel.append(`\n\n$${filePath} stop\n`);
stopProcess.stdout.setEncoding('utf8');
stopProcess.stderr.setEncoding('utf8');
stopProcess.stdout.on('data', (chunk) => {
channel.append(chunk);
});
stopProcess.stderr.on('data', (chunk) => {
channel.append(chunk);
});
stopProcess.on('close', (code) => {
// eslint-disable-next-line no-console
console.log(`crc stop exited with code ${code}`);
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
});
}

static async crcSaveSettings(event) {
Expand Down Expand Up @@ -199,11 +211,11 @@ export default class ClusterViewLoader {

public static async checkCrcStatus(filePath: string, postCommand: string, p: vscode.WebviewPanel | undefined = undefined) {
const crcCredArray = [];
const crcVerInfo = await CliChannel.getInstance().execute(`${filePath} version -ojson`);
channel.append(`\n\n${filePath} version -ojson\n`);
const crcVerInfo = await CliChannel.getInstance().execute(`"${filePath}" version -o json`);
channel.append(`\n\n"${filePath}" version -o json\n`);
channel.append(crcVerInfo.stdout);
const result = await CliChannel.getInstance().execute(`${filePath} status -ojson`);
channel.append(`\n\n${filePath} status -ojson\n`);
const result = await CliChannel.getInstance().execute(`"${filePath}" status -o json`);
channel.append(`\n\n"${filePath}" status -o json\n`);
channel.append(result.stdout);
if (result.error || crcVerInfo.error) {
p.webview.postMessage({action: postCommand, errorStatus: true});
Expand All @@ -216,7 +228,7 @@ export default class ClusterViewLoader {
creds: crcCredArray
});
}
const crcCreds = await CliChannel.getInstance().execute(`${filePath} console --credentials -ojson`);
const crcCreds = await CliChannel.getInstance().execute(`"${filePath}" console --credentials -o json`);
if (!crcCreds.error) {
try {
crcCredArray.push(JSON.parse(crcCreds.stdout).clusterConfig);
Expand Down