Skip to content

Commit

Permalink
fix: correct state during setup
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <[email protected]>
  • Loading branch information
lstocchi committed Sep 17, 2024
1 parent 3b3e1c2 commit f5edaa6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/crc-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 11 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,15 @@ async function initializeCrc(
): Promise<void> {
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}`);
}
Expand Down Expand Up @@ -346,7 +354,7 @@ function registerOpenShiftLocalCluster(
endpoint: {
apiURL,
},
status: () => 'stopped',
status: () => crcStatus.getConnectionStatus(),
};

connectionDisposable = provider.registerKubernetesProviderConnection(kubernetesProviderConnection);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f5edaa6

Please sign in to comment.