Skip to content

Commit

Permalink
fix: remove isNeedSetup variable and rely on actual command to check …
Browse files Browse the repository at this point in the history
…daemon as the value stored could be not up to date with the environment

Signed-off-by: lstocchi <[email protected]>
  • Loading branch information
lstocchi committed May 20, 2024
1 parent ac2a287 commit 58f77f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/crc-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (C) 2023 Red Hat, Inc.
* Copyright (C) 2023-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,15 +20,11 @@ import * as extensionApi from '@podman-desktop/api';
import { execPromise, getCrcCli } from './crc-cli';
import { defaultSetUpPreset, productName } from './util';

export let isNeedSetup = false;

export async function needSetup(): Promise<boolean> {
try {
await execPromise(getCrcCli(), ['setup', '--check-only']);
isNeedSetup = false;
return false;
} catch (e) {
isNeedSetup = true;
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/crc-start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (C) 2023 Red Hat, Inc.
* Copyright (C) 2023-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
***********************************************************************/

import * as extensionApi from '@podman-desktop/api';
import { isNeedSetup, needSetup, setUpCrc } from './crc-setup';
import { needSetup, setUpCrc } from './crc-setup';
import { crcStatus } from './crc-status';
import { commander } from './daemon-commander';
import { crcLogProvider } from './log-provider';
Expand All @@ -44,11 +44,11 @@ export async function startCrc(
});
try {
// call crc setup to prepare bundle, before start
const isNeedSetup = await needSetup();
if (isNeedSetup) {
try {
crcStatus.setSetupRunning(true);
await setUpCrc(logger);
await needSetup();
} catch (error) {
logger.error(error);
provider.updateStatus('stopped');
Expand Down
5 changes: 3 additions & 2 deletions src/crc-status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (C) 2023 Red Hat, Inc.
* Copyright (C) 2023-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@
import * as extensionApi from '@podman-desktop/api';
import type { Status, CrcStatus as CrcStatusApi } from './types';
import { commander } from './daemon-commander';
import { isNeedSetup } from './crc-setup';
import { needSetup } from './crc-setup';

const defaultStatus: Status = { CrcStatus: 'Unknown', Preset: 'openshift' };
const setupStatus: Status = { CrcStatus: 'Need Setup', Preset: 'Unknown' };
Expand Down Expand Up @@ -75,6 +75,7 @@ export class CrcStatus {
}

async initialize(): Promise<void> {
const isNeedSetup = await needSetup();
if (isNeedSetup) {
this._status = setupStatus;
return;
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (C) 2022 Red Hat, Inc.
* Copyright (C) 2022-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@ import { CrcInstall } from './install/crc-install';

import { crcStatus } from './crc-status';
import { startCrc } from './crc-start';
import { isNeedSetup, needSetup, setUpCrc } from './crc-setup';
import { needSetup, setUpCrc } from './crc-setup';
import { deleteCrc, registerDeleteCommand } from './crc-delete';
import { presetChangedEvent, syncPreferences } from './preferences';
import { stopCrc } from './crc-stop';
Expand Down Expand Up @@ -58,8 +58,9 @@ export async function activate(extensionContext: extensionApi.ExtensionContext):
const detectionChecks: extensionApi.ProviderDetectionCheck[] = [];
let status: extensionApi.ProviderStatus = 'not-installed';
let hasDaemonRunning = false;
let isNeedSetup = false;
if (crcVersion) {
await needSetup();
isNeedSetup = await needSetup();

status = 'installed';
if (!isNeedSetup) {
Expand Down

0 comments on commit 58f77f8

Please sign in to comment.