Skip to content

Commit

Permalink
Check for podman machine on CLI instead of relying on odo
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Feb 14, 2024
1 parent 7d19428 commit 008a0f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
14 changes: 0 additions & 14 deletions src/odo/odoWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,6 @@ export class Odo {
);
}

public async isPodmanPresent(): Promise<boolean> {
try {
const result: CliExitData = await this.execute(
new CommandText('odo', 'version -o json'),
);
if ('podman' in JSON.parse(result.stdout)) {
return true;
}
} catch {
//ignore
}
return false;
}

/**
* Bind a component to a bindable service by modifying the devfile
*
Expand Down
21 changes: 16 additions & 5 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as fs from 'fs/promises';
import * as JSYAML from 'js-yaml';
import { platform } from 'os';
import * as path from 'path';
import { which } from 'shelljs';
import { commands, debug, DebugConfiguration, DebugSession, Disposable, EventEmitter, extensions, ProgressLocation, Uri, window, workspace } from 'vscode';
Expand All @@ -15,6 +16,7 @@ import { CommandProvider, StarterProject } from '../odo/componentTypeDescription
import { Odo } from '../odo/odoWrapper';
import { ComponentWorkspaceFolder } from '../odo/workspace';
import sendTelemetry, { NewComponentCommandProps } from '../telemetry';
import { ChildProcessUtil, CliExitData } from '../util/childProcessUtil';
import { Progress } from '../util/progress';
import { vsCommand, VsCommandError } from '../vscommand';
import AddServiceBindingViewLoader, { ServiceBindingFormResponse } from '../webview/add-service-binding/addServiceBindingViewLoader';
Expand Down Expand Up @@ -217,11 +219,20 @@ export class Component extends OpenShiftItem {
}

private static async checkForPodman(): Promise<boolean> {
if (await Odo.Instance.isPodmanPresent()) {
return true;
}
const podmanOnPath = which('podman');
if (podmanOnPath) {
const podmanPath = which('podman');
if (podmanPath) {
if (platform() === 'linux') {
return true;
}
try {
const resultRaw: CliExitData = await ChildProcessUtil.Instance.execute(`"${podmanPath}" machine list --format json`);
const resultObj: { Running: boolean }[] = JSON.parse(resultRaw.stdout);
if (resultObj.length === 1 && resultObj[0].Running) {
return true;
}
} catch (e) {
// do nothing; something is wrong with the podman setup
}
const SETUP_INSTRUCTIONS = 'Open setup instructions';
void window.showErrorMessage('Podman is present on the system, but is not fully set up yet.', SETUP_INSTRUCTIONS)
.then(result => {
Expand Down
7 changes: 0 additions & 7 deletions test/integration/odoWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { expect } from 'chai';
import * as fs from 'fs/promises';
import { suite, suiteSetup } from 'mocha';
import * as path from 'path';
import { which } from 'shelljs';
import * as tmp from 'tmp';
import { promisify } from 'util';
import { Uri, workspace } from 'vscode';
Expand Down Expand Up @@ -165,12 +164,6 @@ suite('./odo/odoWrapper.ts', function () {
expect(componentDetails.starterProjects).is.not.empty;
});

test('isPodmanPresent()', async function() {
const isPodmanPresent = await Odo.Instance.isPodmanPresent();
const whichImplementationPodmanPresent = which('podman') !== null;
expect(isPodmanPresent).to.equal(whichImplementationPodmanPresent);
});

test('getStarterProjects()', async function() {
const starterProjects = await Odo.Instance.getStarterProjects({
registryName: 'DefaultDevfileRegistry',
Expand Down

0 comments on commit 008a0f9

Please sign in to comment.