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

fix: do not remove registries when podman extension is stopping #3136

Merged
merged 1 commit into from Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/podman/src/extension.ts
Expand Up @@ -823,7 +823,7 @@ export async function activate(extensionContext: extensionApi.ExtensionContext):

// register the registries
const registrySetup = new RegistrySetup();
await registrySetup.setup(extensionContext);
await registrySetup.setup();

const podmanConfiguration = new PodmanConfiguration();
await podmanConfiguration.init();
Expand Down
11 changes: 6 additions & 5 deletions extensions/podman/src/registry-setup.ts
Expand Up @@ -49,7 +49,7 @@ export class RegistrySetup {
return path.resolve(podmanConfigContainersPath, 'auth.json');
}

protected async updateRegistries(extensionContext: extensionApi.ExtensionContext): Promise<void> {
protected async updateRegistries(): Promise<void> {
// read the file
const authFile = await this.readAuthFile();
const inFileRegistries: extensionApi.Registry[] = [];
Expand Down Expand Up @@ -77,7 +77,8 @@ export class RegistrySetup {
// For each registry in the file that is not in the inMemory, add it
const toBeAdded = inFileRegistries.filter(fileRegistry => !this.localRegistries.has(fileRegistry.serverUrl));
toBeAdded.forEach(registry => {
extensionContext.subscriptions.push(extensionApi.registry.registerRegistry(registry));
Copy link
Contributor

Choose a reason for hiding this comment

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

That is how I temporary fixed it in my local codebase.

// do not use the disposable from registerRegistry as we want to keep the registry after extension is stopped.
extensionApi.registry.registerRegistry(registry);
this.localRegistries.set(registry.serverUrl, registry);
});
// For each registry in the inMemory that is not in the file, remove it
Expand All @@ -91,7 +92,7 @@ export class RegistrySetup {
});
}

public async setup(extensionContext: extensionApi.ExtensionContext): Promise<void> {
public async setup(): Promise<void> {
extensionApi.registry.registerRegistryProvider({
name: 'podman',
create: function (registryCreateOptions: extensionApi.RegistryCreateOptions): extensionApi.Registry {
Expand Down Expand Up @@ -159,13 +160,13 @@ export class RegistrySetup {

// need to monitor this file
fs.watchFile(this.getAuthFileLocation(), () => {
this.updateRegistries(extensionContext).catch((error: unknown) => {
this.updateRegistries().catch((error: unknown) => {
console.error('Error updating registries', error);
});
});

// else init with the content of this file
await this.updateRegistries(extensionContext);
await this.updateRegistries();
}

protected async readAuthFile(): Promise<ContainersAuthConfigFile> {
Expand Down