-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Add install_format_version to package and reinstall on setup
- Loading branch information
Showing
12 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { upgradePackageInstallVersion } from './upgrade_package_install_version'; |
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/fleet/server/services/setup/upgrade_package_install_version.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; | ||
import pMap from 'p-map'; | ||
import type { Logger } from '@kbn/logging'; | ||
|
||
import { PACKAGES_SAVED_OBJECT_TYPE, SO_SEARCH_LIMIT } from '../../constants'; | ||
import { FLEET_INSTALL_FORMAT_VERSION } from '../../constants/fleet_es_assets'; | ||
import type { Installation } from '../../types'; | ||
|
||
import { reinstallPackageFromInstallation } from '../epm/packages'; | ||
|
||
/** | ||
* Upgrade package install version for packages installed with an older version of Kibana | ||
*/ | ||
export async function upgradePackageInstallVersion({ | ||
soClient, | ||
esClient, | ||
logger, | ||
}: { | ||
soClient: SavedObjectsClientContract; | ||
esClient: ElasticsearchClient; | ||
logger: Logger; | ||
}) { | ||
const res = await soClient.find<Installation>({ | ||
type: PACKAGES_SAVED_OBJECT_TYPE, | ||
perPage: SO_SEARCH_LIMIT, | ||
filter: `${PACKAGES_SAVED_OBJECT_TYPE}.attributes.install_status:installed and (${PACKAGES_SAVED_OBJECT_TYPE}.attributes.install_format_schema_version < ${FLEET_INSTALL_FORMAT_VERSION} or not ${PACKAGES_SAVED_OBJECT_TYPE}.attributes.install_format_schema_version:*)`, | ||
}); | ||
|
||
if (res.total === 0) { | ||
return; | ||
} | ||
|
||
await pMap( | ||
res.saved_objects, | ||
({ attributes: installation }) => { | ||
if (installation.install_source === 'upload') { | ||
return; | ||
} | ||
return reinstallPackageFromInstallation({ | ||
soClient, | ||
esClient, | ||
installation, | ||
}).catch((err) => { | ||
logger.error( | ||
`Package needs to be manually reinstalled ${installation.name} updating install_version failed.` | ||
); | ||
}); | ||
}, | ||
{ concurrency: 10 } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters