Skip to content
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 @@ -11,6 +11,7 @@ import type {
} from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient, Logger } from '@kbn/core/server';

import { USER_SETTINGS_TEMPLATE_SUFFIX } from '../../../../../common/constants';
import type { InstallablePackage, RegistryDataStream } from '../../../../types';
import { getRegistryDataStreamAssetBaseName } from '../../../../../common/services';
const LEGACY_TEMPLATE_SUFFIXES = ['@mappings', '@settings'];
Expand Down Expand Up @@ -108,6 +109,9 @@ export const _filterComponentTemplatesInUse = ({
const usedByLookup = _getIndexTemplatesToUsedByMap(indexTemplates);

return componentTemplateNames.filter((componentTemplateName) => {
if (componentTemplateName.endsWith(USER_SETTINGS_TEMPLATE_SUFFIX)) {
return false;
}
const indexTemplatesUsingComponentTemplate = usedByLookup.get(componentTemplateName);

if (indexTemplatesUsingComponentTemplate?.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';

import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../../common';
import { ElasticsearchAssetType, PACKAGES_SAVED_OBJECT_TYPE } from '../../../../common';

import { packagePolicyService } from '../..';
import { auditLoggingService } from '../../audit_logging';

import { removeInstallation } from './remove';
import { deleteESAssets, removeInstallation } from './remove';

jest.mock('../..', () => {
return {
Expand Down Expand Up @@ -111,3 +112,38 @@ describe('removeInstallation', () => {
});
});
});

describe('deleteESAssets', () => {
it('should not delete @custom components template', async () => {
const esClient = elasticsearchServiceMock.createInternalClient();
await deleteESAssets(
[
{
id: 'logs@custom',
type: ElasticsearchAssetType.componentTemplate,
},
],
esClient
);

expect(esClient.cluster.deleteComponentTemplate).not.toBeCalled();
});

it('should delete @package components template', async () => {
const esClient = elasticsearchServiceMock.createInternalClient();
await deleteESAssets(
[
{
id: 'logs-nginx.access@package',
type: ElasticsearchAssetType.componentTemplate,
},
],
esClient
);

expect(esClient.cluster.deleteComponentTemplate).toBeCalledWith(
{ name: 'logs-nginx.access@package' },
expect.anything()
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PACKAGES_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
USER_SETTINGS_TEMPLATE_SUFFIX,
} from '../../../constants';
import { ElasticsearchAssetType } from '../../../types';
import type {
Expand Down Expand Up @@ -368,7 +369,7 @@ async function deleteIndexTemplate(esClient: ElasticsearchClient, name: string):

async function deleteComponentTemplate(esClient: ElasticsearchClient, name: string): Promise<void> {
// '*' shouldn't ever appear here, but it still would delete all templates
if (name && name !== '*') {
if (name && name !== '*' && !name.endsWith(USER_SETTINGS_TEMPLATE_SUFFIX)) {
try {
await esClient.cluster.deleteComponentTemplate({ name }, { ignore: [404] });
} catch (error) {
Expand Down
Loading