[8.9][Fleet] Fix index patterns being recreated in default space, fix migr… (#164531)

Backport https://github.com/elastic/kibana/pull/164456 to 8.9 (only
index pattern fix)
This commit is contained in:
Julia Bardi 2023-08-23 13:21:11 +02:00 committed by GitHub
parent 5e65000375
commit b3a4723498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -45,7 +45,12 @@ type SavedObjectToBe = Required<Pick<SavedObjectsBulkCreateObject, keyof Archive
};
export type ArchiveAsset = Pick<
SavedObject,
'id' | 'attributes' | 'migrationVersion' | 'references'
| 'id'
| 'attributes'
| 'migrationVersion'
| 'references'
| 'coreMigrationVersion'
| 'typeMigrationVersion'
> & {
type: KibanaSavedObjectType;
};
@ -81,13 +86,23 @@ export async function getKibanaAsset(key: string): Promise<ArchiveAsset> {
export function createSavedObjectKibanaAsset(asset: ArchiveAsset): SavedObjectToBe {
// convert that to an object
return {
const so: Partial<SavedObjectToBe> = {
type: asset.type,
id: asset.id,
attributes: asset.attributes,
references: asset.references || [],
migrationVersion: asset.migrationVersion || {},
};
if (asset.migrationVersion) {
so.migrationVersion = asset.migrationVersion;
}
if (asset.coreMigrationVersion) {
so.coreMigrationVersion = asset.coreMigrationVersion;
}
if (asset.typeMigrationVersion) {
so.typeMigrationVersion = asset.typeMigrationVersion;
}
return so as SavedObjectToBe;
}
export async function installKibanaAssets(options: {

View file

@ -18,6 +18,8 @@ export function getIndexPatternSavedObjects() {
return indexPatternTypes.map((indexPatternType) => ({
id: `${indexPatternType}-*`,
type: INDEX_PATTERN_SAVED_OBJECT_TYPE,
// workaround until https://github.com/elastic/kibana/issues/164454 is fixed
typeMigrationVersion: '8.0.0',
attributes: {
title: `${indexPatternType}-*`,
timeFieldName: '@timestamp',