Skip to content

Commit

Permalink
[Fleet] Missing SO Installation migration (#107214)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Jul 30, 2021
1 parent 0f05ecf commit f2a5cd7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 4 additions & 1 deletion x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
migrateSettingsToV7130,
migrateOutputToV7130,
} from './migrations/to_v7_13_0';
import { migratePackagePolicyToV7140 } from './migrations/to_v7_14_0';
import { migratePackagePolicyToV7140, migrateInstallationToV7140 } from './migrations/to_v7_14_0';
import { migratePackagePolicyToV7150 } from './migrations/to_v7_15_0';

/*
Expand Down Expand Up @@ -320,6 +320,9 @@ const getSavedObjectTypes = (
install_source: { type: 'keyword' },
},
},
migrations: {
'7.14.0': migrateInstallationToV7140,
},
},
[ASSETS_SAVED_OBJECT_TYPE]: {
name: ASSETS_SAVED_OBJECT_TYPE,
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/fleet/server/saved_objects/migrations/to_v7_10_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
EnrollmentAPIKey,
Settings,
AgentAction,
Installation,
} from '../../types';

export const migrateAgentToV7100: SavedObjectMigrationFn<
Expand Down Expand Up @@ -127,12 +126,3 @@ export const migrateAgentActionToV7100 = (
},
});
};

export const migrateInstallationToV7100: SavedObjectMigrationFn<
Exclude<Installation, 'install_source'>,
Installation
> = (installationDoc) => {
installationDoc.attributes.install_source = 'registry';

return installationDoc;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { SavedObjectMigrationFn } from 'kibana/server';

import type { PackagePolicy } from '../../../common';
import type { PackagePolicy, Installation } from '../../../common';

import { migrateEndpointPackagePolicyToV7140 } from './security_solution';

Expand All @@ -27,3 +27,17 @@ export const migratePackagePolicyToV7140: SavedObjectMigrationFn<PackagePolicy,

return updatedPackagePolicyDoc;
};

export const migrateInstallationToV7140: SavedObjectMigrationFn<Installation, Installation> = (
doc
) => {
// Fix a missing migration for user that used Fleet before 7.9
if (!doc.attributes.install_source) {
doc.attributes.install_source = 'registry';
}
if (!doc.attributes.install_version) {
doc.attributes.install_version = doc.attributes.version;
}

return doc;
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default function (providerContext: FtrProviderContext) {
delete packageInfoRes.body.response.savedObject.version;
delete packageInfoRes.body.response.savedObject.updated_at;
delete packageInfoRes.body.response.savedObject.coreMigrationVersion;
delete packageInfoRes.body.response.savedObject.migrationVersion;

expectSnapshot(packageInfoRes.body.response).toMatch();
});
Expand Down

0 comments on commit f2a5cd7

Please sign in to comment.