From c3aab7799b504c485ac5ce53ce1b474e5b708275 Mon Sep 17 00:00:00 2001 From: lstocchi Date: Wed, 21 Aug 2024 10:23:21 +0200 Subject: [PATCH] fix: correct state during setup Signed-off-by: lstocchi --- src/crc-status.ts | 4 ++-- src/extension.ts | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/crc-status.ts b/src/crc-status.ts index cb599085..6b0741a2 100644 --- a/src/crc-status.ts +++ b/src/crc-status.ts @@ -44,7 +44,7 @@ export class CrcStatus { try { // we don't need to update status while setup is going if (this.isSetupGoing) { - this._status = createStatus('Starting', this._status.Preset); + this._status = createStatus('Stopped', this._status.Preset); return; } const oldStatus = this._status; @@ -93,7 +93,7 @@ export class CrcStatus { setSetupRunning(setup: boolean): void { if (setup) { this.isSetupGoing = true; - this._status = createStatus('Starting', this._status.Preset); + this._status = createStatus('Stopped', this._status.Preset); } else { this.isSetupGoing = false; } diff --git a/src/extension.ts b/src/extension.ts index 3277a875..74368049 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -269,7 +269,15 @@ async function initializeCrc( ): Promise { const hasToBeSetup = await needSetup(); if (hasToBeSetup) { - const hasSetupFinished = await setUpCrc(true); + crcStatus.setSetupRunning(true); + let hasSetupFinished = false; + try { + hasSetupFinished = await setUpCrc(true); + } catch (e) { + console.log(String(e)); + } finally { + crcStatus.setSetupRunning(false); + } if (!hasSetupFinished) { throw new Error(`Failed at initializing ${productName}`); } @@ -346,7 +354,7 @@ function registerOpenShiftLocalCluster( endpoint: { apiURL, }, - status: () => 'stopped', + status: () => crcStatus.getConnectionStatus(), }; connectionDisposable = provider.registerKubernetesProviderConnection(kubernetesProviderConnection); @@ -432,6 +440,6 @@ async function presetChanged( // podman connection registerPodmanConnection(provider, extensionContext); } else if (preset === 'openshift' || preset === 'microshift') { - await registerOpenShiftLocalCluster(getPresetLabel(preset), provider, extensionContext, telemetryLogger); + registerOpenShiftLocalCluster(getPresetLabel(preset), provider, extensionContext, telemetryLogger); } }