Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding install method on minikube download #173

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,48 @@ describe('selectVersion', () => {
});
});

describe('install', () => {
test('install should download the asset provided', async () => {
(env.isWindows as boolean) = true;
const release: MinikubeGithubReleaseArtifactMetadata = {
tag: 'v1.2.3',
id: 55,
label: 'v1.5.2',
};

const minikubeDownload = new MinikubeDownload(extensionContext, octokitMock);

vi.spyOn(minikubeDownload, 'download').mockResolvedValue('/download/asset/path');

vi.mocked(processCore.exec).mockResolvedValue({
stdout: '',
stderr: '',
command: '',
});

await minikubeDownload.install(release);
expect(minikubeDownload.download).toHaveBeenCalledWith(release);
});

test('install fallback to download path if install system wide failed', async () => {
(env.isWindows as boolean) = true;
const release: MinikubeGithubReleaseArtifactMetadata = {
tag: 'v1.2.3',
id: 55,
label: 'v1.5.2',
};

const minikubeDownload = new MinikubeDownload(extensionContext, octokitMock);

vi.spyOn(minikubeDownload, 'download').mockResolvedValue('/download/asset/path');

vi.mocked(processCore.exec).mockRejectedValue(new Error('random error'));

const file = await minikubeDownload.install(release);
expect(file).toBe('/download/asset/path');
});
});

describe('findMinikube', () => {
test('should use system wide first', async () => {
(env.isWindows as boolean) = true;
Expand Down
12 changes: 11 additions & 1 deletion src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Octokit } from '@octokit/rest';
import type * as extensionApi from '@podman-desktop/api';
import { env, window } from '@podman-desktop/api';

import { whereBinary } from './util';
import { installBinaryToSystem, whereBinary } from './util';

export interface MinikubeGithubReleaseArtifactMetadata extends extensionApi.QuickPickItem {
tag: string;
Expand Down Expand Up @@ -113,6 +113,16 @@ export class MinikubeDownload {
}
}

async install(release: MinikubeGithubReleaseArtifactMetadata): Promise<string> {
let destFile = await this.download(release);
try {
destFile = await installBinaryToSystem(destFile, 'minikube');
} catch (err: unknown) {
console.debug('Cannot install system wide', err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be reported at error level ?

also is it expected that we don't fail ? (report an error) it's like we're silently ignoring that we can't install it system wide ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I would expect it's an issue if we can't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what is the expected behaviour in the current main branch we have the doUpdate which try to install system wide

https://github.com/containers/podman-desktop-extension-minikube/blob/1ca9e7a481f5a596ddc4b6b45ed893482165bdfe/src/extension.ts#L329-L337

if it fails, just cannot update the binary, and need to restart

The status bar install seems to ask the user:

https://github.com/containers/podman-desktop-extension-minikube/blob/5ba894d30a3a10ab65d3181e0f049f9ff0c01cf1/src/minikube-installer.ts#L151

So my proposal, following your comment would be

  1. download in extension folder
  2. ask user to install system wide ?
  3. yes => try, if fails, create a notification error
  4. no => don't try to install system wide

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems a better way involving the user yes

}
return destFile;
}

// Download minikube from the artifact metadata: MinikubeGithubReleaseArtifactMetadata
// this will download it to the storage bin folder as well as make it executable
// return the path where the file has been downloaded
Expand Down