Skip to content

Commit

Permalink
[Fleet] Allow to exclude packages (#168645)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Oct 11, 2023
1 parent 7708814 commit 4312417
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface FleetConfigType {
min?: string;
max?: string;
};
excludePackages: string[];
};
};
createArtifactsBulkBatchSize?: number;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const config: PluginConfigDescriptor = {
registry: schema.object(
{
kibanaVersionCheckEnabled: schema.boolean({ defaultValue: true }),
excludePackages: schema.arrayOf(schema.string(), { defaultValue: [] }),
spec: schema.object(
{
min: schema.maybe(schema.string()),
Expand Down Expand Up @@ -221,6 +222,7 @@ export const config: PluginConfigDescriptor = {
defaultValue: {
kibanaVersionCheckEnabled: true,
capabilities: [],
excludePackages: [],
spec: {
max: REGISTRY_SPEC_MAX_VERSION,
},
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/fleet/server/services/epm/filtered_packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export function getFilteredSearchPackages() {
if (shouldFilterFleetServer) {
filtered.push(FLEET_SERVER_PACKAGE);
}
return filtered;

const excludePackages = appContextService.getConfig()?.internal?.registry?.excludePackages ?? [];

return filtered.concat(excludePackages);
}

export function getFilteredInstallPackages() {
Expand All @@ -25,5 +28,7 @@ export function getFilteredInstallPackages() {
if (shouldFilterFleetServer) {
filtered.push(FLEET_SERVER_PACKAGE);
}
return filtered;
const excludePackages = appContextService.getConfig()?.internal?.registry?.excludePackages ?? [];

return filtered.concat(excludePackages);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ describe('_installPackage', () => {
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
excludePackages: [],
},
},
})
Expand Down Expand Up @@ -197,6 +198,7 @@ describe('_installPackage', () => {
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
excludePackages: [],
},
},
})
Expand Down Expand Up @@ -271,6 +273,7 @@ describe('_installPackage', () => {
registry: {
kibanaVersionCheckEnabled: true,
capabilities: [],
excludePackages: [],
},
},
})
Expand Down
30 changes: 30 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/packages/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,36 @@ test: invalid manifest
});
expect(packages.find((item) => item.id === 'fleet_server')).toBeUndefined();
});

it('should filter packages configured in xpack.fleet.internal.registry.excludePackages', async () => {
const mockContract = createAppContextStartContractMock({
internal: {
registry: {
excludePackages: ['nginx'],
},
},
} as any);
appContextService.start(mockContract);

const soClient = savedObjectsClientMock.create();
soClient.find.mockResolvedValue({
saved_objects: [
{
id: 'nginx',
attributes: {
name: 'nginx',
version: '0.0.1',
install_source: 'upload',
install_version: '0.0.1',
},
},
],
} as any);
const packages = await getPackages({
savedObjectsClient: soClient,
});
expect(packages.find((item) => item.id === 'nginx')).toBeUndefined();
});
});

describe('getInstalledPackages', () => {
Expand Down

0 comments on commit 4312417

Please sign in to comment.