Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Fleet] set typeMigrationVersion instead of migrationVersion
(#164712)](#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":"[email protected]"},"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//issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nhttps://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\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//issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nhttps://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\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//issues/154246\r\nReplacing it
with `typeMigrationVersion` using the same logic as in\r\nkibana
core:\r\n\r\nhttps://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\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 <[email protected]>
  • Loading branch information
kibanamachine and juliaElastic authored Aug 24, 2023
1 parent 128fde2 commit 8548581
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 @@ -47,7 +47,7 @@ export type ArchiveAsset = Pick<
SavedObject,
| 'id'
| 'attributes'
| 'migrationVersion'
| 'migrationVersion' // deprecated
| 'references'
| 'coreMigrationVersion'
| 'typeMigrationVersion'
Expand Down Expand Up @@ -93,8 +93,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 8548581

Please sign in to comment.