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
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,21 @@
"title": "Open Add CRC Cluster Wizard",
"category": "OpenShift"
},
{
"command": "openshift.explorer.addCluster.crcSetup",
"title": "Run CRC Setup Command",
"category": "OpenShift"
},
{
"command": "openshift.explorer.addCluster.crcStart",
"title": "Run CRC Setup Command",
"category": "OpenShift"
},
{
"command": "openshift.explorer.addCluster.crcStop",
"title": "Run CRC Setup Command",
"category": "OpenShift"
},
{
"command": "openshift.component.revealContextInExplorer",
"title": "Reveal in Explorer"
Expand Down Expand Up @@ -1065,6 +1080,18 @@
"command": "openshift.explorer.addCluster.openCreateClusterPage",
"when": "false"
},
{
"command": "openshift.explorer.addCluster.crcSetup",
"when": "false"
},
{
"command": "openshift.explorer.addCluster.crcStart",
"when": "false"
},
{
"command": "openshift.explorer.addCluster.crcStop",
"when": "false"
},
{
"command": "openshift.component.revealInExplorer",
"when": "false"
Expand Down
61 changes: 39 additions & 22 deletions src/webview/cluster/app/clusterView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ export default function addClusterView(props) {
const steps = getSteps();

const setCrcStatus = (message) => {
setStatus({ crcStatus: message.status.crcStatus,
openshiftStatus: message.status.openshiftStatus,
diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A',
cacheUsage: prettyBytes(message.status.cacheUsage),
cacheDir: message.status.cacheDir,
crcVer: message.versionInfo.version,
openshiftVer: message.versionInfo.openshiftVersion,
creds: message.creds
});
setStatus({
crcStatus: message.status.crcStatus,
openshiftStatus: message.status.openshiftStatus,
diskUsage: message.status.diskUsage ? prettyBytes(message.status.diskUsage) : 'N/A',
cacheUsage: prettyBytes(message.status.cacheUsage),
cacheDir: message.status.cacheDir,
crcVer: message.versionInfo.version,
openshiftVer: message.versionInfo.openshiftVersion,
creds: message.creds
});
}

const messageListener = (event) => {
Expand Down Expand Up @@ -167,25 +168,41 @@ export default function addClusterView(props) {
setProgress(true);
setCrcStartError(false);
if (settingPresent) {
props.vscode.postMessage({action: 'start', 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`;

props.vscode.postMessage({action: 'start',
data: crcStartCommand,
pullSecret: pullSecretPath,
crcLoc: fileName,
cpuSize,
memory,
isSetting: false
});
props.vscode.postMessage({
action: 'crcStart',
data: crcStartCommand,
pullSecret: pullSecretPath,
crcLoc: fileName,
cpuSize,
memory,
nameserver: crcNameserver,
isSetting: false
});
}
}
const SaveSettings = 2;

const handleSaveSettings = ()=> {
props.vscode.postMessage({
action: 'crcSaveSettings',
pullSecret: pullSecretPath,
crcLoc: fileName,
cpuSize,
memory,
nameserver: crcNameserver
});
}

const handleNext = () => {
if (activeStep === steps.length - 1) {
handleStartProcess()
} else if (activeStep === SaveSettings) {
handleSaveSettings();
}
setActiveStep((prevActiveStep) => prevActiveStep + 1);
};
Expand All @@ -202,21 +219,21 @@ export default function addClusterView(props) {
const handleStopProcess = () => {
setStopProgress(true);
setCrcStopError(false);
props.vscode.postMessage({action: 'stop', data: `${fileName}`});
props.vscode.postMessage({action: 'crcStop', data: `${fileName}`});
}

const handleCrcSetup = () => {
props.vscode.postMessage({action: 'run', data: `${fileName}` })
props.vscode.postMessage({action: 'crcSetup', data: `${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.scode.postMessage({action: 'checksetting'});
props.vscode.postMessage({action: 'checksetting'});
} else {
props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
}
Expand Down
145 changes: 94 additions & 51 deletions src/webview/cluster/clusterViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,96 @@ let panel: vscode.WebviewPanel;

const channel: vscode.OutputChannel = vscode.window.createOutputChannel('CRC Logs');

/*
interface ViewEvent {
action: string;
}


interface OpenPageEvent extends ViewEvent {
params: {
url: string;
}
}

interface CrcStartEvent extends ViewEvent {
data: string;
pullSecret: string;
crcLoc: string;
cpuSize: number;
memory: number;
isSetting: boolean;
}
*/
async function clusterEditorMessageListener (event: any ): Promise<any> {
if (['openLaunchSandboxPage', 'openCreateClusterPage', 'openCrcAddClusterPage'].includes(event.action)) {
await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event.params?.url);
switch (event.action) {
case 'openLaunchSandboxPage':
case 'openCreateClusterPage':
case 'openCrcAddClusterPage':
case 'crcSetup':
case 'crcStart':
case 'crcStop':
await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event);
break;

case 'crcSaveSettings':
ClusterViewLoader.crcSaveSettings(event);
break;

case 'checksetting':
const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
if (binaryFromSetting) {
panel.webview.postMessage({action: 'crcsetting'});
ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel);
}
break;

case 'checkcrcstatus':
ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel);
break

case 'crcLogin':
vscode.commands.executeCommand(
'openshift.explorer.login.credentialsLogin',
true,
event.url,
event.data.username,
event.data.password
);
break;
}
}

export default class ClusterViewLoader {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
static get extensionPath() {
return vscode.extensions.getExtension(ExtenisonID).extensionPath
}

if (event.action === 'run') {
@vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage')
static async openLaunchSandboxPage(url: string) {
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

@vsCommand('openshift.explorer.addCluster.openCreateClusterPage')
static async openCreateClusterPage(url: string) {
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
static async openCrcAddClusterPage() {
// fake command to report crc selection through telemetry
}

@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.show();
}
if (event.action === 'start') {

@vsCommand('openshift.explorer.addCluster.crcStart')
static async crcStart(event: any) {
let startProcess: ChildProcess;
channel.show();
if (event.isSetting) {
Expand All @@ -37,11 +116,6 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
startProcess = spawn(`${binaryFromSetting}`, crcOptions);
channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`);
} else {
const configuration = vscode.workspace.getConfiguration('openshiftConnector');
configuration.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global);
configuration.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global);
configuration.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global);
configuration.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global);
const [tool, ...params] = event.data.split(' ');
startProcess = spawn(tool, params);
channel.append(`\n\n${tool} ${params.join(' ')}\n`);
Expand All @@ -64,7 +138,9 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel);
});
}
if (event.action === 'stop') {

@vsCommand('openshift.explorer.addCluster.crcStop')
static async crcStop(event) {
let filePath: string;
channel.show();
if (event.data === '') {
Expand All @@ -88,47 +164,14 @@ async function clusterEditorMessageListener (event: any ): Promise<any> {
ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel);
});
}
if (event.action === 'checksetting') {
const binaryFromSetting:string = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation');
if (binaryFromSetting) {
panel.webview.postMessage({action: 'crcsetting'});
ClusterViewLoader.checkCrcStatus(binaryFromSetting, 'crcstatus', panel);
}
}
if (event.action === 'checkcrcstatus') {
ClusterViewLoader.checkCrcStatus(event.data, 'crcstatus', panel);
}

if (event.action === 'crclogin') {
vscode.commands.executeCommand(
'openshift.explorer.login.credentialsLogin',
true,
event.url,
event.data.username,
event.data.password
);
}
}

export default class ClusterViewLoader {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
static get extensionPath() {
return vscode.extensions.getExtension(ExtenisonID).extensionPath
}

@vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage')
static async openLaunchSandboxPage(url: string) {
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

@vsCommand('openshift.explorer.addCluster.openCreateClusterPage')
static async openCreateClusterPage(url: string) {
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
static async openCrcAddClusterPage(url: string) {
// fake command to report crc selection through telemetry
static async crcSaveSettings(event) {
const cfg = vscode.workspace.getConfiguration('openshiftConnector');
await cfg.update('crcBinaryLocation', event.crcLoc, vscode.ConfigurationTarget.Global);
await cfg.update('crcPullSecretPath', event.pullSecret, vscode.ConfigurationTarget.Global);
await cfg.update('crcCpuCores', event.cpuSize, vscode.ConfigurationTarget.Global);
await cfg.update('crcMemoryAllocated', Number.parseInt(event.memory, 10), vscode.ConfigurationTarget.Global);
await cfg.update('crcNameserver', event.nameserver);
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand Down Expand Up @@ -192,7 +235,7 @@ export default class ClusterViewLoader {
const reactAppUri = p.webview.asWebviewUri(reactAppPathOnDisk);
const htmlString:Buffer = fs.readFileSync(path.join(reactAppRootOnDisk, 'index.html'));
const meta = `<meta http-equiv="Content-Security-Policy"
content="connect-src *;
content="connect-src *;
default-src 'none';
img-src ${p.webview.cspSource} https: 'self' data:;
script-src 'unsafe-eval' 'unsafe-inline' vscode-resource:;
Expand Down