Skip to content

Commit e306126

Browse files
committed
Check for podman machine on CLI instead of relying on odo
Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent dc9c140 commit e306126

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/odo/odoWrapper.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,6 @@ export class Odo {
359359
);
360360
}
361361

362-
public async isPodmanPresent(): Promise<boolean> {
363-
try {
364-
const result: CliExitData = await this.execute(
365-
new CommandText('odo', 'version -o json'),
366-
);
367-
if ('podman' in JSON.parse(result.stdout)) {
368-
return true;
369-
}
370-
} catch {
371-
//ignore
372-
}
373-
return false;
374-
}
375-
376362
/**
377363
* Bind a component to a bindable service by modifying the devfile
378364
*

src/openshift/component.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as fs from 'fs/promises';
77
import * as JSYAML from 'js-yaml';
8+
import { platform } from 'os';
89
import * as path from 'path';
910
import { which } from 'shelljs';
1011
import { commands, debug, DebugConfiguration, DebugSession, Disposable, EventEmitter, extensions, ProgressLocation, Uri, window, workspace } from 'vscode';
@@ -15,6 +16,7 @@ import { CommandProvider, StarterProject } from '../odo/componentTypeDescription
1516
import { Odo } from '../odo/odoWrapper';
1617
import { ComponentWorkspaceFolder } from '../odo/workspace';
1718
import sendTelemetry, { NewComponentCommandProps } from '../telemetry';
19+
import { ChildProcessUtil, CliExitData } from '../util/childProcessUtil';
1820
import { Progress } from '../util/progress';
1921
import { vsCommand, VsCommandError } from '../vscommand';
2022
import AddServiceBindingViewLoader, { ServiceBindingFormResponse } from '../webview/add-service-binding/addServiceBindingViewLoader';
@@ -217,11 +219,20 @@ export class Component extends OpenShiftItem {
217219
}
218220

219221
private static async checkForPodman(): Promise<boolean> {
220-
if (await Odo.Instance.isPodmanPresent()) {
221-
return true;
222-
}
223-
const podmanOnPath = which('podman');
224-
if (podmanOnPath) {
222+
const podmanPath = which('podman');
223+
if (podmanPath) {
224+
if (platform() === 'linux') {
225+
return true;
226+
}
227+
try {
228+
const resultRaw: CliExitData = await ChildProcessUtil.Instance.execute(`"${podmanPath}" machine list --format json`);
229+
const resultObj: { Running: boolean }[] = JSON.parse(resultRaw.stdout);
230+
if (resultObj.length === 1 && resultObj[0].Running) {
231+
return true;
232+
}
233+
} catch (e) {
234+
// do nothing; something is wrong with the podman setup
235+
}
225236
const SETUP_INSTRUCTIONS = 'Open setup instructions';
226237
void window.showErrorMessage('Podman is present on the system, but is not fully set up yet.', SETUP_INSTRUCTIONS)
227238
.then(result => {

test/integration/odoWrapper.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { expect } from 'chai';
88
import * as fs from 'fs/promises';
99
import { suite, suiteSetup } from 'mocha';
1010
import * as path from 'path';
11-
import { which } from 'shelljs';
1211
import * as tmp from 'tmp';
1312
import { promisify } from 'util';
1413
import { Uri, workspace } from 'vscode';
@@ -172,12 +171,6 @@ suite('./odo/odoWrapper.ts', function () {
172171
expect(componentDetails.starterProjects).is.not.empty;
173172
});
174173

175-
test('isPodmanPresent()', async function() {
176-
const isPodmanPresent = await Odo.Instance.isPodmanPresent();
177-
const whichImplementationPodmanPresent = which('podman') !== null;
178-
expect(isPodmanPresent).to.equal(whichImplementationPodmanPresent);
179-
});
180-
181174
test('getStarterProjects()', async function() {
182175
const starterProjects = await Odo.Instance.getStarterProjects({
183176
registryName: 'DefaultDevfileRegistry',

0 commit comments

Comments
 (0)