From 70d4fde8d9245f00e86eb3db4623362ba892775f Mon Sep 17 00:00:00 2001 From: lstocchi Date: Fri, 2 Aug 2024 11:56:38 +0200 Subject: [PATCH 1/7] fix: handle error so that it is shown in both page and task manager Signed-off-by: lstocchi --- src/crc-setup.ts | 3 ++- src/crc-start.ts | 22 ++++++++++----------- src/extension.ts | 39 ++++++++++---------------------------- src/install/crc-install.ts | 2 +- src/log-provider.ts | 4 ++-- src/preferences.ts | 4 ++-- src/util.ts | 10 ++++++++++ 7 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/crc-setup.ts b/src/crc-setup.ts index cd8e46e3..7a156afc 100644 --- a/src/crc-setup.ts +++ b/src/crc-setup.ts @@ -25,12 +25,13 @@ export async function needSetup(): Promise { await execPromise(getCrcCli(), ['setup', '--check-only']); return false; } catch (e) { + console.log(e) return true; } } // eslint-disable-next-line @typescript-eslint/no-unused-vars -export async function setUpCrc(logger: extensionApi.Logger, askForPreset = false): Promise { +export async function setUpCrc(askForPreset = false): Promise { if (askForPreset) { const preset = await extensionApi.window.showInformationMessage( 'Which preset bundle would you like to use with OpenShift Local. MicroShift, provides a lightweight and optimized environment with a limited set of services. OpenShift, provides a single node OpenShift cluster with a fuller set of services, including a web console (requires more resources).', diff --git a/src/crc-start.ts b/src/crc-start.ts index dfdc3f03..6028d5c0 100644 --- a/src/crc-start.ts +++ b/src/crc-start.ts @@ -37,7 +37,7 @@ const missingPullSecret = 'Failed to ask for pull secret'; export async function startCrc( provider: extensionApi.Provider, - logger: extensionApi.Logger, + loggerCallback: (data: string) => void, telemetryLogger: extensionApi.TelemetryLogger, ): Promise { telemetryLogger.logUsage('crc.start', { @@ -49,16 +49,15 @@ export async function startCrc( if (isNeedSetup) { try { crcStatus.setSetupRunning(true); - await setUpCrc(logger); + await setUpCrc(); } catch (error) { - logger.error(error); provider.updateStatus('stopped'); - return; + throw error; } finally { crcStatus.setSetupRunning(false); } } - await crcLogProvider.startSendingLogs(logger); + crcLogProvider.startSendingLogs(loggerCallback); const result = await commander.start(); if (result.Status === 'Running') { provider.updateStatus('started'); @@ -72,11 +71,11 @@ export async function startCrc( // check that crc missing pull secret if (err.message.startsWith(missingPullSecret)) { // ask user to provide pull secret - if (await askAndStorePullSecret(logger)) { + if (await askAndStorePullSecret()) { // if pull secret provided try to start again - return startCrc(provider, logger, telemetryLogger); + return startCrc(provider, loggerCallback, telemetryLogger); } else { - throw new Error('Could not start without pullsecret!'); + throw new Error(`${productName} start error: VM cannot be started without the pullsecret`); } } else if (err.name === 'RequestError' && err.code === 'ECONNRESET') { // look like crc start normally, but we receive empty response from socket, so 'got' generate an error @@ -84,14 +83,14 @@ export async function startCrc( return true; } } - await extensionApi.window.showErrorMessage(`${productName} start error: ${err}`); - console.error(err); + console.error(err); provider.updateStatus('stopped'); + throw new Error(`${productName} start error: ${err}`); } return false; } -async function askAndStorePullSecret(logger: extensionApi.Logger): Promise { +async function askAndStorePullSecret(): Promise { let pullSecret: string; const authSession: extensionApi.AuthenticationSession | undefined = await extensionApi.authentication.getSession( 'redhat.authentication-provider', @@ -147,7 +146,6 @@ async function askAndStorePullSecret(logger: extensionApi.Logger): Promise { // we already have an instance - if (crcStatus.status.CrcStatus !== 'No Cluster' && !isNeedSetup()) { + if (crcStatus.status.CrcStatus !== 'No Cluster') { return; } - if (isNeedSetup()) { - const initResult = await initializeCrc(provider, extensionContext, telemetryLogger, logger); - if (!initResult) { - throw new Error(`${productName} not initialized.`); - } - } - - const hasStarted = await startCrc(provider, logger, telemetryLogger); + const hasStarted = await startCrc(provider, getLoggerCallback(undefined, logger), telemetryLogger); if (!connectionDisposable && hasStarted) { addCommands(telemetryLogger); await presetChanged(provider, extensionContext, telemetryLogger); } } -async function initializeCrc( - provider: extensionApi.Provider, - extensionContext: extensionApi.ExtensionContext, - telemetryLogger: extensionApi.TelemetryLogger, - logger: extensionApi.Logger, -): Promise { - const hasSetupFinished = await setUpCrc(logger, true); - if (hasSetupFinished) { - await needSetup(); - await connectToCrc(); - await presetChanged(provider, extensionContext, telemetryLogger); - addCommands(telemetryLogger); - await syncPreferences(provider, extensionContext, telemetryLogger); - } - return hasSetupFinished; -} - function addCommands(telemetryLogger: extensionApi.TelemetryLogger): void { registerOpenTerminalCommand(); registerOpenConsoleCommand(); @@ -353,9 +329,14 @@ function registerOpenShiftLocalCluster( delete: () => { return handleDelete(provider, extensionContext, telemetryLogger); }, - start: async ctx => { + start: async (ctx, logger) => { provider.updateStatus('starting'); - await startCrc(provider, ctx.log, telemetryLogger); + try { + await startCrc(provider, getLoggerCallback(ctx, logger,), telemetryLogger); + } catch (e) { + logger?.error(e); + throw e; + } }, stop: () => { provider.updateStatus('stopping'); diff --git a/src/install/crc-install.ts b/src/install/crc-install.ts index d747f5b4..eb8196a5 100644 --- a/src/install/crc-install.ts +++ b/src/install/crc-install.ts @@ -136,7 +136,7 @@ export class CrcInstall { provider.updateVersion(newInstalledCrc.version); let setupResult = false; if (await needSetup()) { - setupResult = await setUpCrc(logger, true); + setupResult = await setUpCrc(true); } installFinishedFn(setupResult, newInstalledCrc); } diff --git a/src/log-provider.ts b/src/log-provider.ts index 6f9056ed..e07b0ab5 100644 --- a/src/log-provider.ts +++ b/src/log-provider.ts @@ -24,14 +24,14 @@ export class LogProvider { private timeout: NodeJS.Timeout; constructor(private readonly commander: DaemonCommander) {} - async startSendingLogs(logger: Logger): Promise { + async startSendingLogs(loggerCallback: (data: string) => void): Promise { let lastLogLine = 0; this.timeout = setInterval(async () => { try { const logs = await this.commander.logs(); const logsDiff: string[] = logs.Messages.slice(lastLogLine, logs.Messages.length - 1); lastLogLine = logs.Messages.length; - logger.log(logsDiff.join('\n')); + loggerCallback(logsDiff.join('\n')); } catch (e) { console.log('Logs tick: ' + e); } diff --git a/src/preferences.ts b/src/preferences.ts index b4777796..e1251623 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -19,7 +19,7 @@ import * as extensionApi from '@podman-desktop/api'; import type { Configuration, Preset } from './types.js'; import { commander } from './daemon-commander.js'; -import { isEmpty, productName } from './util.js'; +import { getLoggerCallback, isEmpty, productName } from './util.js'; import { crcStatus } from './crc-status.js'; import { stopCrc } from './crc-stop.js'; import { deleteCrc } from './crc-delete.js'; @@ -337,7 +337,7 @@ async function handleRecreate( } else if (result === 'Delete and Restart') { await stopCrc(telemetryLogger); await deleteCrc(); - await startCrc(provider, defaultLogger, telemetryLogger); + await startCrc(provider, getLoggerCallback(undefined, defaultLogger), telemetryLogger); return true; } else if (result === 'Delete') { await deleteCrc(); diff --git a/src/util.ts b/src/util.ts index 7598f8d4..93720fd6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -20,6 +20,7 @@ import * as os from 'node:os'; import { spawn } from 'node:child_process'; import * as fs from 'node:fs/promises'; import type { Preset } from './types.js'; +import { LifecycleContext, Logger } from '@podman-desktop/api'; export const productName = 'OpenShift Local'; export const defaultPreset: Preset = 'openshift'; @@ -113,3 +114,12 @@ export function getPresetLabel(preset: Preset): string { return defaultPresetLabel; } } + +export function getLoggerCallback(context?: LifecycleContext, logger?: Logger): (data: string) => void { + return (data: string): void => { + if (data) { + context?.log?.log(data); + logger?.log(data); + } + }; +} From 9a9dd2e5364b0c6bb2e7bfc3686598eaa49267fb Mon Sep 17 00:00:00 2001 From: lstocchi Date: Fri, 2 Aug 2024 15:28:07 +0200 Subject: [PATCH 2/7] fix: clean + test Signed-off-by: lstocchi --- src/crc-setup.ts | 3 +-- src/crc-start.spec.ts | 5 +++-- src/extension.ts | 5 ++--- src/log-provider.ts | 1 - src/util.spec.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ src/util.ts | 2 +- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/util.spec.ts diff --git a/src/crc-setup.ts b/src/crc-setup.ts index 7a156afc..7509de47 100644 --- a/src/crc-setup.ts +++ b/src/crc-setup.ts @@ -25,12 +25,11 @@ export async function needSetup(): Promise { await execPromise(getCrcCli(), ['setup', '--check-only']); return false; } catch (e) { - console.log(e) + console.log(e); return true; } } -// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function setUpCrc(askForPreset = false): Promise { if (askForPreset) { const preset = await extensionApi.window.showInformationMessage( diff --git a/src/crc-start.spec.ts b/src/crc-start.spec.ts index 3d5521b1..80416fa1 100644 --- a/src/crc-start.spec.ts +++ b/src/crc-start.spec.ts @@ -24,6 +24,7 @@ import { startCrc } from './crc-start.js'; import * as logProvider from './log-provider.js'; import * as daemon from './daemon-commander.js'; import type { StartInfo } from './types.js'; +import { getLoggerCallback } from './util.js'; vi.mock('@podman-desktop/api', async () => { return { @@ -44,7 +45,7 @@ test('setUpCRC is skipped if already setup, it just perform the daemon start com { updateStatus: vi.fn(), } as unknown as extensionApi.Provider, - {} as extensionApi.Logger, + getLoggerCallback(), { logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger, ); expect(setUpMock).not.toBeCalled(); @@ -65,7 +66,7 @@ test('set up CRC and then start the daemon', async () => { { updateStatus: vi.fn(), } as unknown as extensionApi.Provider, - {} as extensionApi.Logger, + getLoggerCallback(), { logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger, ); expect(setUpMock).toBeCalled(); diff --git a/src/extension.ts b/src/extension.ts index 93ec9a71..17ce9e67 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -30,7 +30,6 @@ import { CrcInstall } from './install/crc-install.js'; import { crcStatus } from './crc-status.js'; import { startCrc } from './crc-start.js'; -import { needSetup, setUpCrc } from './crc-setup.js'; import { deleteCrc, registerDeleteCommand } from './crc-delete.js'; import { presetChangedEvent, saveConfig, syncPreferences } from './preferences.js'; import { stopCrc } from './crc-stop.js'; @@ -332,9 +331,9 @@ function registerOpenShiftLocalCluster( start: async (ctx, logger) => { provider.updateStatus('starting'); try { - await startCrc(provider, getLoggerCallback(ctx, logger,), telemetryLogger); + await startCrc(provider, getLoggerCallback(ctx, logger), telemetryLogger); } catch (e) { - logger?.error(e); + logger.error(e); throw e; } }, diff --git a/src/log-provider.ts b/src/log-provider.ts index e07b0ab5..5b499c9e 100644 --- a/src/log-provider.ts +++ b/src/log-provider.ts @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 ***********************************************************************/ -import type { Logger } from '@podman-desktop/api'; import type { DaemonCommander } from './daemon-commander.js'; import { commander } from './daemon-commander.js'; diff --git a/src/util.spec.ts b/src/util.spec.ts new file mode 100644 index 00000000..74ed5680 --- /dev/null +++ b/src/util.spec.ts @@ -0,0 +1,43 @@ +/********************************************************************** + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +import type * as extensionApi from '@podman-desktop/api'; +import { expect, test, vi } from 'vitest'; +import { getLoggerCallback } from './util'; + +test('check logger passed to getLoggerCallback is actually called with data', async () => { + const logMock = vi.fn(); + const logger = { + log: logMock, + } as unknown as extensionApi.Logger; + const callback = getLoggerCallback(undefined, logger); + callback('data'); + expect(logMock).toBeCalledWith('data'); +}); + +test('check logger passed to getLoggerCallback is actually called with data', async () => { + const logMock = vi.fn(); + const context = { + log: { + log: logMock, + }, + } as unknown as extensionApi.LifecycleContext; + const callback = getLoggerCallback(context); + callback('data2'); + expect(logMock).toBeCalledWith('data2'); +}); \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index 93720fd6..9859e73a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -20,7 +20,7 @@ import * as os from 'node:os'; import { spawn } from 'node:child_process'; import * as fs from 'node:fs/promises'; import type { Preset } from './types.js'; -import { LifecycleContext, Logger } from '@podman-desktop/api'; +import type { LifecycleContext, Logger } from '@podman-desktop/api'; export const productName = 'OpenShift Local'; export const defaultPreset: Preset = 'openshift'; From 9dbfcedeaba61d83a837f6a3ac5b4c7f6a2c52c1 Mon Sep 17 00:00:00 2001 From: lstocchi Date: Fri, 2 Aug 2024 15:36:46 +0200 Subject: [PATCH 3/7] fix: fix formatter Signed-off-by: lstocchi --- src/crc-start.ts | 2 +- src/extension.ts | 50 +++++++++++++++++++++++++++++++++--------------- src/util.spec.ts | 34 ++++++++++++++++---------------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/crc-start.ts b/src/crc-start.ts index 6028d5c0..80fa792e 100644 --- a/src/crc-start.ts +++ b/src/crc-start.ts @@ -83,7 +83,7 @@ export async function startCrc( return true; } } - console.error(err); + console.error(err); provider.updateStatus('stopped'); throw new Error(`${productName} start error: ${err}`); } diff --git a/src/extension.ts b/src/extension.ts index 17ce9e67..1845b9ff 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -37,9 +37,9 @@ import { registerOpenTerminalCommand } from './dev-terminal.js'; import { commandManager } from './command.js'; import { registerOpenConsoleCommand } from './crc-console.js'; import { registerLogInCommands } from './login-commands.js'; -import { defaultLogger } from './logger.js'; import { pushImageToCrcCluster } from './image-handler.js'; import type { Preset } from './types.js'; +import { needSetup, setUpCrc } from './crc-setup.js'; const CRC_PUSH_IMAGE_TO_CLUSTER = 'crc.image.push.to.cluster'; const CRC_PRESET_KEY = 'crc.crcPreset'; @@ -220,9 +220,7 @@ function registerProviderConnectionFactory( ): void { connectionFactoryDisposable = provider.setKubernetesProviderConnectionFactory( { - initialize: async () => { - await createCrcVm(provider, extensionContext, telemetryLogger, defaultLogger); - }, + initialize: () => initializeCrc(provider, extensionContext, telemetryLogger), create: async (params, logger) => { await presetChanged(provider, extensionContext, telemetryLogger); await saveConfig(params); @@ -258,16 +256,38 @@ async function createCrcVm( } } +async function initializeCrc( + provider: extensionApi.Provider, + extensionContext: extensionApi.ExtensionContext, + telemetryLogger: extensionApi.TelemetryLogger, +): Promise { + const hasSetupFinished = await setUpCrc(true); + if (!hasSetupFinished) { + throw new Error(`Failed at initializing ${productName}`); + } + + await needSetup(); + await connectToCrc(); + await presetChanged(provider, extensionContext, telemetryLogger); + addCommands(telemetryLogger); + await syncPreferences(provider, extensionContext, telemetryLogger); + return presetChanged(provider, extensionContext, telemetryLogger); +} + function addCommands(telemetryLogger: extensionApi.TelemetryLogger): void { - registerOpenTerminalCommand(); - registerOpenConsoleCommand(); - registerLogInCommands(); - registerDeleteCommand(); - - commandManager.addCommand(CRC_PUSH_IMAGE_TO_CLUSTER, image => { - telemetryLogger.logUsage('pushImage'); - return pushImageToCrcCluster(image); - }); + try { + registerOpenTerminalCommand(); + registerOpenConsoleCommand(); + registerLogInCommands(); + registerDeleteCommand(); + + commandManager.addCommand(CRC_PUSH_IMAGE_TO_CLUSTER, image => { + telemetryLogger.logUsage('pushImage'); + pushImageToCrcCluster(image); + }); + } catch (e) { + // do nothing + } } function deleteCommands(): void { @@ -335,7 +355,7 @@ function registerOpenShiftLocalCluster( } catch (e) { logger.error(e); throw e; - } + } }, stop: () => { provider.updateStatus('stopping'); @@ -406,6 +426,6 @@ async function presetChanged( // podman connection registerPodmanConnection(provider, extensionContext); } else if (preset === 'openshift' || preset === 'microshift') { - registerOpenShiftLocalCluster(getPresetLabel(preset), provider, extensionContext, telemetryLogger); + await registerOpenShiftLocalCluster(getPresetLabel(preset), provider, extensionContext, telemetryLogger); } } diff --git a/src/util.spec.ts b/src/util.spec.ts index 74ed5680..a01153cc 100644 --- a/src/util.spec.ts +++ b/src/util.spec.ts @@ -21,23 +21,23 @@ import { expect, test, vi } from 'vitest'; import { getLoggerCallback } from './util'; test('check logger passed to getLoggerCallback is actually called with data', async () => { - const logMock = vi.fn(); - const logger = { - log: logMock, - } as unknown as extensionApi.Logger; - const callback = getLoggerCallback(undefined, logger); - callback('data'); - expect(logMock).toBeCalledWith('data'); + const logMock = vi.fn(); + const logger = { + log: logMock, + } as unknown as extensionApi.Logger; + const callback = getLoggerCallback(undefined, logger); + callback('data'); + expect(logMock).toBeCalledWith('data'); }); test('check logger passed to getLoggerCallback is actually called with data', async () => { - const logMock = vi.fn(); - const context = { - log: { - log: logMock, - }, - } as unknown as extensionApi.LifecycleContext; - const callback = getLoggerCallback(context); - callback('data2'); - expect(logMock).toBeCalledWith('data2'); -}); \ No newline at end of file + const logMock = vi.fn(); + const context = { + log: { + log: logMock, + }, + } as unknown as extensionApi.LifecycleContext; + const callback = getLoggerCallback(context); + callback('data2'); + expect(logMock).toBeCalledWith('data2'); +}); From 749192bc03408e8001530a33507f58dec6c398e7 Mon Sep 17 00:00:00 2001 From: lstocchi Date: Tue, 20 Aug 2024 18:16:10 +0200 Subject: [PATCH 4/7] fix: initialize Signed-off-by: lstocchi --- src/crc-start.ts | 2 +- src/extension.ts | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/crc-start.ts b/src/crc-start.ts index 80fa792e..18aedd3c 100644 --- a/src/crc-start.ts +++ b/src/crc-start.ts @@ -57,7 +57,7 @@ export async function startCrc( crcStatus.setSetupRunning(false); } } - crcLogProvider.startSendingLogs(loggerCallback); + await crcLogProvider.startSendingLogs(loggerCallback); const result = await commander.start(); if (result.Status === 'Running') { provider.updateStatus('started'); diff --git a/src/extension.ts b/src/extension.ts index 1845b9ff..6c675066 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -218,13 +218,19 @@ function registerProviderConnectionFactory( extensionContext: extensionApi.ExtensionContext, telemetryLogger: extensionApi.TelemetryLogger, ): void { + let justInitialized = false; connectionFactoryDisposable = provider.setKubernetesProviderConnectionFactory( { - initialize: () => initializeCrc(provider, extensionContext, telemetryLogger), + initialize: async () => { + await initializeCrc(provider, extensionContext, telemetryLogger); + justInitialized = true; + }, create: async (params, logger) => { + justInitialized = false; await presetChanged(provider, extensionContext, telemetryLogger); await saveConfig(params); - if (params['crc.factory.start.now']) { + if (params['crc.factory.start.now'] || justInitialized) { + await connectToCrc(); await createCrcVm(provider, extensionContext, telemetryLogger, logger); } }, @@ -261,17 +267,18 @@ async function initializeCrc( extensionContext: extensionApi.ExtensionContext, telemetryLogger: extensionApi.TelemetryLogger, ): Promise { - const hasSetupFinished = await setUpCrc(true); - if (!hasSetupFinished) { - throw new Error(`Failed at initializing ${productName}`); + const hasToBeSetup = await needSetup(); + if (hasToBeSetup) { + const hasSetupFinished = await setUpCrc(true); + if (!hasSetupFinished) { + throw new Error(`Failed at initializing ${productName}`); + } } - await needSetup(); - await connectToCrc(); - await presetChanged(provider, extensionContext, telemetryLogger); addCommands(telemetryLogger); await syncPreferences(provider, extensionContext, telemetryLogger); - return presetChanged(provider, extensionContext, telemetryLogger); + await presetChanged(provider, extensionContext, telemetryLogger); + provider.updateStatus('configured'); } function addCommands(telemetryLogger: extensionApi.TelemetryLogger): void { @@ -283,7 +290,7 @@ function addCommands(telemetryLogger: extensionApi.TelemetryLogger): void { commandManager.addCommand(CRC_PUSH_IMAGE_TO_CLUSTER, image => { telemetryLogger.logUsage('pushImage'); - pushImageToCrcCluster(image); + pushImageToCrcCluster(image).catch((e: unknown) => console.error(String(e))); }); } catch (e) { // do nothing @@ -333,14 +340,13 @@ function registerOpenShiftLocalCluster( extensionContext: extensionApi.ExtensionContext, telemetryLogger: extensionApi.TelemetryLogger, ): void { - const status = () => crcStatus.getConnectionStatus(); const apiURL = 'https://api.crc.testing:6443'; const kubernetesProviderConnection: extensionApi.KubernetesProviderConnection = { name, endpoint: { apiURL, }, - status, + status: () => 'stopped', }; connectionDisposable = provider.registerKubernetesProviderConnection(kubernetesProviderConnection); From 9bc1a31d1cb8013634f3c8d28c7e092912819391 Mon Sep 17 00:00:00 2001 From: lstocchi Date: Wed, 21 Aug 2024 10:23:21 +0200 Subject: [PATCH 5/7] 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 888f8cbe..4469903f 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 6c675066..26820131 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); } } From 8f7687e66fbdccc28d35107e6c13807aa933001f Mon Sep 17 00:00:00 2001 From: lstocchi Date: Wed, 21 Aug 2024 10:31:14 +0200 Subject: [PATCH 6/7] fix: position variable Signed-off-by: lstocchi --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 26820131..8f940ae9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -226,10 +226,10 @@ function registerProviderConnectionFactory( justInitialized = true; }, create: async (params, logger) => { - justInitialized = false; await presetChanged(provider, extensionContext, telemetryLogger); await saveConfig(params); if (params['crc.factory.start.now'] || justInitialized) { + justInitialized = false; await connectToCrc(); await createCrcVm(provider, extensionContext, telemetryLogger, logger); } From a8b14dc02b71132b4584b426caac84ed912378c9 Mon Sep 17 00:00:00 2001 From: lstocchi Date: Tue, 17 Sep 2024 10:42:49 +0200 Subject: [PATCH 7/7] fix: enableunixSockets when pulling secret Signed-off-by: lstocchi --- src/daemon-commander.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/daemon-commander.ts b/src/daemon-commander.ts index c6b9a3b0..8c8f05f6 100644 --- a/src/daemon-commander.ts +++ b/src/daemon-commander.ts @@ -129,6 +129,7 @@ export class DaemonCommander { // eslint-disable-next-line @typescript-eslint/no-explicit-any const response = await (got as any).post(url, { body: value, + enableUnixSockets: true, throwHttpErrors: false, retry: { limit: 0,