Skip to content

Commit f6de767

Browse files
committed
[Fleet] fix duplicate ingest pipeline refs (#82078)
* check if pipeline refs for version already exists * use the right version
1 parent fe48a65 commit f6de767

File tree

2 files changed

+254
-177
lines changed

2 files changed

+254
-177
lines changed

x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/ingest_pipeline/install.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
import * as Registry from '../../registry';
1515
import { CallESAsCurrentUser } from '../../../../types';
1616
import { saveInstalledEsRefs } from '../../packages/install';
17+
import { getInstallationObject } from '../../packages';
18+
import { deletePipelineRefs } from './remove';
1719

1820
interface RewriteSubstitution {
1921
source: string;
@@ -31,6 +33,7 @@ export const installPipelines = async (
3133
// it can be created pointing to the new template, without removing the old one and effecting data
3234
// so do not remove the currently installed pipelines here
3335
const dataStreams = installablePackage.data_streams;
36+
const { name: pkgName, version: pkgVersion } = installablePackage;
3437
if (!dataStreams?.length) return [];
3538
const pipelinePaths = paths.filter((path) => isPipeline(path));
3639
// get and save pipeline refs before installing pipelines
@@ -50,6 +53,20 @@ export const installPipelines = async (
5053
acc.push(...pipelineObjectRefs);
5154
return acc;
5255
}, []);
56+
57+
// check that we don't duplicate the pipeline refs if the user is reinstalling
58+
const installedPkg = await getInstallationObject({
59+
savedObjectsClient,
60+
pkgName,
61+
});
62+
if (!installedPkg) throw new Error("integration wasn't found while installing pipelines");
63+
// remove the current pipeline refs, if any exist, associated with this version before saving new ones so no duplicates occur
64+
await deletePipelineRefs(
65+
savedObjectsClient,
66+
installedPkg.attributes.installed_es,
67+
pkgName,
68+
pkgVersion
69+
);
5370
await saveInstalledEsRefs(savedObjectsClient, installablePackage.name, pipelineRefs);
5471
const pipelines = dataStreams.reduce<Array<Promise<EsAssetReference[]>>>((acc, dataStream) => {
5572
if (dataStream.ingest_pipeline) {

0 commit comments

Comments
 (0)