Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 7b2f19f

Browse files
committed
clean extensions code and update stopLoop to stop monitoring when deactivating
Signed-off-by: lstocchi <[email protected]>
1 parent c574ece commit 7b2f19f

File tree

2 files changed

+31
-68
lines changed

2 files changed

+31
-68
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
"format": "file",
2020
"scope": "ContainerProviderConnectionFactory",
2121
"default": "/Users/luca/.crc/machines/crc/crc_test.img",
22-
"description": "Image Path (Optional)"
22+
"description": "Image Path"
2323
},
24-
"macadam.factory.machine.image-uri": {
24+
"macadam.factory.machine.ssh-identity-path": {
2525
"type": "string",
26+
"format": "file",
2627
"scope": "ContainerProviderConnectionFactory",
27-
"description": "Image URL or image reference (Optional)",
28-
"placeholder": "Use 'registry/org/image:version' for image reference"
28+
"default": "/Users/luca/.crc/machines/crc/id_ecdsa",
29+
"description": "Ssh Identity Path"
2930
},
3031
"macadam.factory.machine.cpus": {
3132
"type": "number",

src/extension.ts

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { getErrorMessage } from './utils';
2828
const MACADAM_CLI_NAME = 'macadam';
2929
const MACADAM_DISPLAY_NAME = 'Macadam';
3030
const MACADAM_MARKDOWN = `Podman Desktop can help you run RHEL and other linux-based VM by using Macadam.\n\nMore information: Link to macadam here`;
31-
const stopLoop = false;
31+
let stopLoop = false;
3232

3333
type StatusHandler = (name: string, event: extensionApi.ProviderConnectionStatus) => void;
3434
const macadamMachinesInfo = new Map<string, MachineInfo>();
@@ -117,12 +117,19 @@ async function getJSONMachineList(macadam: Macadam): Promise<MachineJSONListOutp
117117
try {
118118
const macadamCli = await macadam.getExecutable();
119119
const { stdout, stderr } = await extensionApi.process.exec(macadamCli, ['list']);
120-
list.push(...(JSON.parse(stdout) as MachineJSON[]));
120+
console.log(stdout);
121+
if (stdout !== '') {
122+
console.log("stdout");
123+
list.push(...(JSON.parse(stdout) as MachineJSON[]));
124+
}
121125
error = stderr;
122126
} catch (err) {
123127
error = getErrorMessage(err);
124128
}
125129

130+
console.log(list.length);
131+
console.log(error);
132+
126133
return { list, error };
127134
}
128135

@@ -186,7 +193,6 @@ async function registerProviderFor(
186193
macadam: Macadam,
187194
provider: extensionApi.Provider,
188195
machineInfo: MachineInfo,
189-
socketPath: string,
190196
context: extensionApi.ExtensionContext,
191197
): Promise<void> {
192198
const lifecycle: extensionApi.ProviderConnectionLifecycle = {
@@ -207,6 +213,8 @@ async function registerProviderFor(
207213
const providerConnectionShellAccess = new ProviderConnectionShellAccessImpl(machineInfo);
208214
context.subscriptions.push(providerConnectionShellAccess);
209215

216+
// we are not really working with a containerProviderConnection of type podman
217+
// however it offers most of the things we would need, so it is good for a POC
210218
const containerProviderConnection: extensionApi.ContainerProviderConnection = {
211219
name: 'macadam',
212220
displayName: 'Macadam',
@@ -215,14 +223,10 @@ async function registerProviderFor(
215223
shellAccess: providerConnectionShellAccess,
216224
lifecycle,
217225
endpoint: {
218-
socketPath,
226+
socketPath: 'no-socket',
219227
},
220228
};
221229

222-
// Since Podman 4.5, machines are using the same path for all sockets of machines
223-
// so a machine is not distinguishable from another one.
224-
// monitorPodmanSocket(socketPath, machineInfo.name);
225-
226230
const disposable = provider.registerContainerProviderConnection(containerProviderConnection);
227231
provider.updateStatus('ready');
228232

@@ -246,6 +250,8 @@ async function updateMachines(
246250
// init machines available
247251
const machineListOutput = await getJSONMachineList(macadam);
248252

253+
console.log('qui');
254+
249255
if (machineListOutput.error) {
250256
// TODO handle the error
251257
}
@@ -308,7 +314,6 @@ async function updateMachines(
308314
macadam,
309315
provider,
310316
podmanMachineInfo,
311-
'/var/folders/n4/n5hyrstd2739lcy9903jn8f40000gn/T/podman/macadam.sock',
312317
context,
313318
);
314319
}
@@ -434,72 +439,24 @@ async function createVM(
434439
telemetryRecords.OS = 'mac';
435440
}
436441

437-
/* To be uncommented when init command will support these flags
438-
// cpu
439-
if (params['macadam.factory.machine.cpus']) {
440-
const cpusValue = params['macadam.factory.machine.cpus'];
441-
parameters.push('--cpus');
442-
parameters.push(cpusValue);
443-
telemetryRecords.cpus = cpusValue;
444-
}
445-
446-
// memory
447-
if (params['macadam.factory.machine.memory']) {
448-
parameters.push('--memory');
449-
const memoryAsMiB = +params['macadam.factory.machine.memory'] / (1024 * 1024);
450-
// Hyper-V requires VMs to have memory in 2 MB increments. So we round it
451-
const roundedMemoryMiB = Math.floor((memoryAsMiB + 1) / 2) * 2;
452-
parameters.push(roundedMemoryMiB.toString());
453-
telemetryRecords.memory = params['macadam.factory.machine.memory'];
454-
}
455-
456-
// disk size
457-
if (params['macadam.factory.machine.diskSize']) {
458-
parameters.push('--disk-size');
459-
const diskAsGiB = +params['macadam.factory.machine.diskSize'] / (1024 * 1024 * 1024);
460-
parameters.push(Math.floor(diskAsGiB).toString());
461-
telemetryRecords.diskSize = params['macadam.factory.machine.diskSize'];
462-
}
463-
*/
464-
465442
// image-path
466443
const imagePath = params['macadam.factory.machine.image-path'];
467444
if (imagePath) {
468445
parameters.push(imagePath);
469446
telemetryRecords.imagePath = 'custom';
470447
}
471448

449+
// ssh identity path
450+
const sshIdentityPath = params['macadam.factory.machine.ssh-identity-path'];
451+
if (sshIdentityPath) {
452+
parameters.push('--ssh-identity-path');
453+
parameters.push(sshIdentityPath);
454+
}
455+
472456
// push args for demo
473-
parameters.push('--ssh-identity-path');
474-
parameters.push(path.join(path.dirname(imagePath), 'id_ed25519'));
475457
parameters.push('--username');
476458
parameters.push('core');
477459

478-
/* else if (params['macadam.factory.machine.image-uri']) {
479-
const imageUri = params['macadam.factory.machine.image-uri'].trim();
480-
parameters.push('--image-path');
481-
if (imageUri.startsWith('https://') || imageUri.startsWith('http://')) {
482-
parameters.push(imageUri);
483-
telemetryRecords.imagePath = 'custom-url';
484-
} else {
485-
parameters.push(`docker://${imageUri}`);
486-
telemetryRecords.imagePath = 'custom-registry';
487-
}
488-
} */
489-
490-
/* if (!telemetryRecords.imagePath) {
491-
telemetryRecords.imagePath = 'default';
492-
} */
493-
494-
// name at the end
495-
/* if (params['macadam.factory.machine.name']) {
496-
parameters.push(params['macadam.factory.machine.name']);
497-
telemetryRecords.customName = params['macadam.factory.machine.name'];
498-
telemetryRecords.defaultName = false;
499-
} else {
500-
telemetryRecords.defaultName = true;
501-
} */
502-
503460
const startTime = performance.now();
504461
try {
505462
const macadamCli = await macadam.getExecutable();
@@ -522,3 +479,8 @@ async function createVM(
522479
//sendTelemetryRecords('macadam.machine.init', telemetryRecords, false);
523480
}
524481
}
482+
483+
export function deactivate(): void {
484+
stopLoop = true;
485+
console.log('stopping macadam extension');
486+
}

0 commit comments

Comments
 (0)