Skip to content

Commit

Permalink
[Fleet] set typeMigrationVersion instead of migrationVersion (#164712)
Browse files Browse the repository at this point in the history
## Summary

Fix #164690

`migrationVersion` was removed from es mapping in 8.8:
#154246
Replacing it with `typeMigrationVersion` using the same logic as in
kibana core:

https://github.com/elastic/kibana/blob/ba843882a7bb35aa3062efd6562ed85d5db157f4/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/document_migrator/migrations/transform_migration_version.ts#L17


To verify:
- add Kubernetes integration to a new policy
- verify that it is added successfully

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
juliaElastic authored Aug 24, 2023
1 parent e911038 commit 0146dc8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jest.mock('timers/promises', () => ({
async setTimeout() {},
}));

import { installKibanaSavedObjects } from './install';
import { createSavedObjectKibanaAsset, installKibanaSavedObjects } from './install';

const mockLogger = loggingSystemMock.createLogger();

Expand Down Expand Up @@ -122,3 +122,27 @@ describe('installKibanaSavedObjects', () => {
expect(mockImporter.resolveImportErrors).toHaveBeenCalledTimes(1);
});
});

describe('createSavedObjectKibanaAsset', () => {
it('should set migrationVersion as typeMigrationVersion in so', () => {
const asset = createAsset({
attributes: { hello: 'world' },
migrationVersion: { dashboard: '8.6.0' },
});
const result = createSavedObjectKibanaAsset(asset);

expect(result.typeMigrationVersion).toEqual('8.6.0');
});

it('should set coreMigrationVersion and typeMigrationVersion in so', () => {
const asset = createAsset({
attributes: { hello: 'world' },
typeMigrationVersion: '8.6.0',
coreMigrationVersion: '8.7.0',
});
const result = createSavedObjectKibanaAsset(asset);

expect(result.typeMigrationVersion).toEqual('8.6.0');
expect(result.coreMigrationVersion).toEqual('8.7.0');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type ArchiveAsset = Pick<
SavedObject,
| 'id'
| 'attributes'
| 'migrationVersion'
| 'migrationVersion' // deprecated
| 'references'
| 'coreMigrationVersion'
| 'typeMigrationVersion'
Expand Down Expand Up @@ -99,8 +99,9 @@ export function createSavedObjectKibanaAsset(asset: ArchiveAsset): SavedObjectTo
references: asset.references || [],
};

if (asset.migrationVersion) {
so.migrationVersion = asset.migrationVersion;
// migrating deprecated migrationVersion to typeMigrationVersion
if (asset.migrationVersion && asset.migrationVersion[asset.type]) {
so.typeMigrationVersion = asset.migrationVersion[asset.type];
}
if (asset.coreMigrationVersion) {
so.coreMigrationVersion = asset.coreMigrationVersion;
Expand Down

0 comments on commit 0146dc8

Please sign in to comment.