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

[Ingest Manager] Remove package cache on package uninstall #76873

Merged
merged 3 commits into from
Sep 8, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getInstallation, savedObjectTypes } from './index';
import { deletePipeline } from '../elasticsearch/ingest_pipeline/';
import { installIndexPatterns } from '../kibana/index_pattern/install';
import { packagePolicyService, appContextService } from '../..';
import { splitPkgKey } from '../registry';
import { splitPkgKey, deletePackageCache, getArchiveInfo } from '../registry';

skh marked this conversation as resolved.
Show resolved Hide resolved
export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
Expand All @@ -22,7 +22,7 @@ export async function removeInstallation(options: {
}): Promise<AssetReference[]> {
const { savedObjectsClient, pkgkey, callCluster } = options;
// TODO: the epm api should change to /name/version so we don't need to do this
const { pkgName } = splitPkgKey(pkgkey);
const { pkgName, pkgVersion } = splitPkgKey(pkgkey);
const installation = await getInstallation({ savedObjectsClient, pkgName });
if (!installation) throw Boom.badRequest(`${pkgName} is not installed`);
if (installation.removable === false)
Expand Down Expand Up @@ -50,6 +50,11 @@ export async function removeInstallation(options: {
// could also update with [] or some other state
await savedObjectsClient.delete(PACKAGES_SAVED_OBJECT_TYPE, pkgName);

// remove the package archive and its contents from the cache so that a reinstall fetches
// a fresh copy from the registry
const paths = await getArchiveInfo(pkgName, pkgVersion);
deletePackageCache(pkgName, pkgVersion, paths);

// successful delete's in SO client return {}. return something more useful
return installedAssets;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export const getArchiveLocation = (name: string, version: string) =>

export const setArchiveLocation = (name: string, version: string, location: string) =>
archiveLocationCache.set(pkgToPkgKey({ name, version }), location);

export const deleteArchiveLocation = (name: string, version: string) =>
archiveLocationCache.delete(pkgToPkgKey({ name, version }));
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import {
RegistrySearchResults,
RegistrySearchResult,
} from '../../../types';
import { cacheGet, cacheSet, cacheHas, getArchiveLocation, setArchiveLocation } from './cache';
import {
cacheGet,
cacheSet,
cacheDelete,
cacheHas,
getArchiveLocation,
setArchiveLocation,
deleteArchiveLocation,
} from './cache';
import { ArchiveEntry, untarBuffer, unzipBuffer } from './extract';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
Expand Down Expand Up @@ -241,3 +249,17 @@ export function groupPathsByService(paths: string[]): AssetsGroupedByServiceByTy
// elasticsearch: assets.elasticsearch,
};
}

export const deletePackageCache = (name: string, version: string, paths: string[]) => {
const archiveLocation = getArchiveLocation(name, version);
if (archiveLocation) {
// delete cached archive
cacheDelete(archiveLocation);

// delete cached archive location
deleteArchiveLocation(name, version);
}
// delete cached archive contents
// this has been populated in Registry.getArchiveInfo()
paths.forEach((path) => cacheDelete(path));
};