[8.10] [Fleet] set typeMigrationVersion instead of migrationVersion (#164712) (#164727)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Fleet] set typeMigrationVersion instead of migrationVersion
(#164712)](https://github.com/elastic/kibana/pull/164712)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Bardi","email":"90178898+juliaElastic@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-08-24T14:37:58Z","message":"[Fleet]
set typeMigrationVersion instead of migrationVersion (#164712)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/164690\r\n\r\n`migrationVersion`
was removed from es mapping in
8.8:\r\nhttps://github.com/elastic/kibana/issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nba843882a7/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/document_migrator/migrations/transform_migration_version.ts (L17)\r\n\r\n\r\nTo
verify:\r\n- add Kubernetes integration to a new policy\r\n- verify that
it is added successfully\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"0146dc87e8db9ed085295ad63d5863f2964d4eb6","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.10.0","v8.11.0","v8.9.2"],"number":164712,"url":"https://github.com/elastic/kibana/pull/164712","mergeCommit":{"message":"[Fleet]
set typeMigrationVersion instead of migrationVersion (#164712)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/164690\r\n\r\n`migrationVersion`
was removed from es mapping in
8.8:\r\nhttps://github.com/elastic/kibana/issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nba843882a7/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/document_migrator/migrations/transform_migration_version.ts (L17)\r\n\r\n\r\nTo
verify:\r\n- add Kubernetes integration to a new policy\r\n- verify that
it is added successfully\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"0146dc87e8db9ed085295ad63d5863f2964d4eb6"}},"sourceBranch":"main","suggestedTargetBranches":["8.10","8.9"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164712","number":164712,"mergeCommit":{"message":"[Fleet]
set typeMigrationVersion instead of migrationVersion (#164712)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/164690\r\n\r\n`migrationVersion`
was removed from es mapping in
8.8:\r\nhttps://github.com/elastic/kibana/issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nba843882a7/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/document_migrator/migrations/transform_migration_version.ts (L17)\r\n\r\n\r\nTo
verify:\r\n- add Kubernetes integration to a new policy\r\n- verify that
it is added successfully\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"0146dc87e8db9ed085295ad63d5863f2964d4eb6"}},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-08-24 11:57:53 -04:00 committed by GitHub
parent c538a872f3
commit c3a088bb5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View file

@ -19,7 +19,7 @@ jest.mock('timers/promises', () => ({
async setTimeout() {},
}));
import { installKibanaSavedObjects } from './install';
import { createSavedObjectKibanaAsset, installKibanaSavedObjects } from './install';
const mockLogger = loggingSystemMock.createLogger();
@ -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');
});
});

View file

@ -53,7 +53,7 @@ export type ArchiveAsset = Pick<
SavedObject,
| 'id'
| 'attributes'
| 'migrationVersion'
| 'migrationVersion' // deprecated
| 'references'
| 'coreMigrationVersion'
| 'typeMigrationVersion'
@ -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;