Skip to content

Commit f4fb342

Browse files
committed
CRC commands does not work in case of full path has spaces (#2320)
* CRC commands does not work in case of full path has spaces This PR fixes #2319. Signed-off-by: Denis Golovin [email protected]
1 parent 1e24e84 commit f4fb342

File tree

3 files changed

+83
-38
lines changed

3 files changed

+83
-38
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,12 @@
15801580
"type": "number",
15811581
"default": 9216,
15821582
"description": "MiB of memory to allocate to the OpenShift cluster as selected during the first run"
1583+
},
1584+
"openshiftConnector.crcNameserver": {
1585+
"Title": "CRC Domain Name Server",
1586+
"type": "string",
1587+
"default": "",
1588+
"description": "IP address/name of DNS to use with CRC"
15831589
}
15841590
}
15851591
}

src/webview/cluster/app/clusterView.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export default function addClusterView(props) {
7878
const [statusError, setStatusError] = React.useState(false);
7979

8080
React.useEffect(() => {
81-
props.vscode.postMessage({action: 'checksetting'});
81+
props.vscode.postMessage({
82+
action: 'checksetting'
83+
});
8284
}, []);
8385

8486
const steps = getSteps();
@@ -168,14 +170,18 @@ export default function addClusterView(props) {
168170
setProgress(true);
169171
setCrcStartError(false);
170172
if (settingPresent) {
171-
props.vscode.postMessage({action: 'crcStart', isSetting: true });
173+
props.vscode.postMessage({
174+
action: 'crcStart', isSetting: true
175+
});
172176
} else {
173-
const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`:
174-
`${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`;
177+
const nameServerOpt = crcNameserver ? `-n ${crcNameserver}` : '';
175178

176179
props.vscode.postMessage({
177180
action: 'crcStart',
178-
data: crcStartCommand,
181+
data: {
182+
tool: fileName,
183+
options: `start -p "${pullSecretPath}" -c ${cpuSize} -m ${memory} ${nameServerOpt} -o json`
184+
},
179185
pullSecret: pullSecretPath,
180186
crcLoc: fileName,
181187
cpuSize,
@@ -219,23 +225,44 @@ export default function addClusterView(props) {
219225
const handleStopProcess = () => {
220226
setStopProgress(true);
221227
setCrcStopError(false);
222-
props.vscode.postMessage({action: 'crcStop', data: `${fileName}`});
228+
props.vscode.postMessage({
229+
action: 'crcStop',
230+
data: {
231+
tool: fileName
232+
}
233+
});
223234
}
224235

225236
const handleCrcSetup = () => {
226-
props.vscode.postMessage({action: 'crcSetup', data: `${fileName}` })
237+
props.vscode.postMessage({
238+
action: 'crcSetup',
239+
data: {
240+
tool: fileName
241+
}
242+
})
227243
}
228244

229245
const handleCrcLogin = (loginDetails, clusterUrl) => {
230-
props.vscode.postMessage({action: 'crcLogin', data: loginDetails, url: clusterUrl })
246+
props.vscode.postMessage({
247+
action: 'crcLogin',
248+
data: loginDetails,
249+
url: clusterUrl
250+
})
231251
}
232252

233253
const handleRefresh = () => {
234254
setStatusSkeleton(true);
235255
if (settingPresent) {
236-
props.vscode.postMessage({action: 'checksetting'});
256+
props.vscode.postMessage({
257+
action: 'checksetting'
258+
});
237259
} else {
238-
props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
260+
props.vscode.postMessage({
261+
action: 'checkcrcstatus',
262+
data: {
263+
tool: fileName
264+
}
265+
});
239266
}
240267
}
241268

src/webview/cluster/clusterViewLoader.ts

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class ClusterViewLoader {
9999
@vsCommand('openshift.explorer.addCluster.crcSetup')
100100
static async crcSetup(event: any) {
101101
const terminal: vscode.Terminal = WindowUtil.createTerminal('OpenShift: CRC Setup', undefined);
102-
terminal.sendText(`${event.data} setup`);
102+
terminal.sendText(`"${event.data.tool}" setup`);
103103
terminal.show();
104104
}
105105

@@ -112,13 +112,15 @@ export default class ClusterViewLoader {
112112
const pullSecretFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcPullSecretPath');
113113
const cpuFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcCpuCores');
114114
const memoryFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcMemoryAllocated');
115-
const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, '-ojson'];
115+
const nameserver = vscode.workspace.getConfiguration('openshiftConnector').get<string>('crcNameserver');
116+
const nameserverOption = nameserver ? ['-n', nameserver] : [];
117+
const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, ...nameserverOption, '-o json'];
118+
116119
startProcess = spawn(`${binaryFromSetting}`, crcOptions);
117-
channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`);
120+
channel.append(`\n\n"${binaryFromSetting}" ${crcOptions.join(' ')}\n`);
118121
} else {
119-
const [tool, ...params] = event.data.split(' ');
120-
startProcess = spawn(tool, params);
121-
channel.append(`\n\n${tool} ${params.join(' ')}\n`);
122+
startProcess = spawn(`${event.data.tool}`, event.data.options.split(' '));
123+
channel.append(`\n\n"${event.data.tool}" ${event.data.options}\n`);
122124
}
123125
startProcess.stdout.setEncoding('utf8');
124126
startProcess.stderr.setEncoding('utf8');
@@ -137,32 +139,42 @@ export default class ClusterViewLoader {
137139
const binaryLoc = event.isSetting ? vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'): event.crcLoc;
138140
ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel);
139141
});
142+
startProcess.on('error', (err) => {
143+
console.log(err);
144+
});
140145
}
141146

142147
@vsCommand('openshift.explorer.addCluster.crcStop')
143148
static async crcStop(event) {
144149
let filePath: string;
145150
channel.show();
146-
if (event.data === '') {
151+
if (event.data.tool === '') {
147152
filePath = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
148153
} else {
149-
filePath = event.data;
154+
filePath = event.data.tool;
155+
}
156+
try {
157+
const stopProcess = spawn(`${filePath}`, ['stop']);
158+
channel.append(`\n\n"${filePath}" stop\n`);
159+
stopProcess.stdout.setEncoding('utf8');
160+
stopProcess.stderr.setEncoding('utf8');
161+
stopProcess.stdout.on('data', (chunk) => {
162+
channel.append(chunk);
163+
});
164+
stopProcess.stderr.on('data', (chunk) => {
165+
channel.append(chunk);
166+
});
167+
stopProcess.on('close', (code) => {
168+
// eslint-disable-next-line no-console
169+
console.log(`crc stop exited with code ${code}`);
170+
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
171+
});
172+
stopProcess.on('error', (err) => {
173+
console.log(err);
174+
});
175+
} catch(err) {
176+
console.log(err);
150177
}
151-
const stopProcess = spawn(`${filePath}`, ['stop']);
152-
channel.append(`\n\n$${filePath} stop\n`);
153-
stopProcess.stdout.setEncoding('utf8');
154-
stopProcess.stderr.setEncoding('utf8');
155-
stopProcess.stdout.on('data', (chunk) => {
156-
channel.append(chunk);
157-
});
158-
stopProcess.stderr.on('data', (chunk) => {
159-
channel.append(chunk);
160-
});
161-
stopProcess.on('close', (code) => {
162-
// eslint-disable-next-line no-console
163-
console.log(`crc stop exited with code ${code}`);
164-
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
165-
});
166178
}
167179

168180
static async crcSaveSettings(event) {
@@ -199,11 +211,11 @@ export default class ClusterViewLoader {
199211

200212
public static async checkCrcStatus(filePath: string, postCommand: string, p: vscode.WebviewPanel | undefined = undefined) {
201213
const crcCredArray = [];
202-
const crcVerInfo = await CliChannel.getInstance().execute(`${filePath} version -ojson`);
203-
channel.append(`\n\n${filePath} version -ojson\n`);
214+
const crcVerInfo = await CliChannel.getInstance().execute(`"${filePath}" version -o json`);
215+
channel.append(`\n\n"${filePath}" version -o json\n`);
204216
channel.append(crcVerInfo.stdout);
205-
const result = await CliChannel.getInstance().execute(`${filePath} status -ojson`);
206-
channel.append(`\n\n${filePath} status -ojson\n`);
217+
const result = await CliChannel.getInstance().execute(`"${filePath}" status -o json`);
218+
channel.append(`\n\n"${filePath}" status -o json\n`);
207219
channel.append(result.stdout);
208220
if (result.error || crcVerInfo.error) {
209221
p.webview.postMessage({action: postCommand, errorStatus: true});
@@ -216,7 +228,7 @@ export default class ClusterViewLoader {
216228
creds: crcCredArray
217229
});
218230
}
219-
const crcCreds = await CliChannel.getInstance().execute(`${filePath} console --credentials -ojson`);
231+
const crcCreds = await CliChannel.getInstance().execute(`"${filePath}" console --credentials -o json`);
220232
if (!crcCreds.error) {
221233
try {
222234
crcCredArray.push(JSON.parse(crcCreds.stdout).clusterConfig);

0 commit comments

Comments
 (0)