-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Changes to bulk upgrade api for allowing rolling upgrades (#1…
…31947) * [Fleet] Changes to bulk upgrade api for allowing rolling upgrades * Remove one query and some tests * Skip version check if fleet server agents are being upgraded * Fix test * Fixing tests again * Fix failing check * Fix another test * Fix another test * Fix api integration tests * Remove parameter Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
- Loading branch information
1 parent
61ae132
commit 44fb932
Showing
6 changed files
with
367 additions
and
87 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/fleet/common/services/get_max_version.test.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,40 @@ | ||
/* | ||
* 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 { getMaxVersion } from './get_max_version'; | ||
|
||
describe('Fleet - getMaxVersion', () => { | ||
it('returns the maximum version', () => { | ||
const versions = ['8.1.0', '8.3.0', '8.2.1', '7.16.0', '8.2.0', '7.16.1', '8.3.1']; | ||
expect(getMaxVersion(versions)).toEqual('8.3.1'); | ||
}); | ||
|
||
it('returns the maximum version when there are duplicates', () => { | ||
const versions = ['8.1.0', '8.3.0', '8.2.1', '7.16.0', '8.2.0', '7.16.1', '8.2.0', '7.15.1']; | ||
expect(getMaxVersion(versions)).toEqual('8.3.0'); | ||
}); | ||
|
||
it('returns the maximum version when there is a snapshot version', () => { | ||
const versions = ['8.1.0', '8.2.0-SNAPSHOT', '7.16.0', '7.16.1']; | ||
expect(getMaxVersion(versions)).toEqual('8.2.0-SNAPSHOT'); | ||
}); | ||
|
||
it('returns the maximum version and prefers the major version to the snapshot', () => { | ||
const versions = ['8.1.0', '8.2.0-SNAPSHOT', '8.2.0', '7.16.0', '7.16.1']; | ||
expect(getMaxVersion(versions)).toEqual('8.2.0'); | ||
}); | ||
|
||
it('when there is only a version returns it', () => { | ||
const versions = ['8.1.0']; | ||
expect(getMaxVersion(versions)).toEqual('8.1.0'); | ||
}); | ||
|
||
it('returns an empty string when the passed array is empty', () => { | ||
const versions: string[] = []; | ||
expect(getMaxVersion(versions)).toEqual(''); | ||
}); | ||
}); |
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,23 @@ | ||
/* | ||
* 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 { uniq } from 'lodash'; | ||
import semverGt from 'semver/functions/gt'; | ||
import semverCoerce from 'semver/functions/coerce'; | ||
|
||
// Find max version from an array of string versions | ||
export function getMaxVersion(versions: string[]) { | ||
const uniqVersions: string[] = uniq(versions); | ||
|
||
if (uniqVersions.length === 1) { | ||
const semverVersion = semverCoerce(uniqVersions[0])?.version; | ||
return semverVersion ? semverVersion : ''; | ||
} else if (uniqVersions.length > 1) { | ||
const sorted = uniqVersions.sort((a, b) => (semverGt(a, b) ? 1 : -1)); | ||
return sorted[sorted.length - 1]; | ||
} | ||
return ''; | ||
} |
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
Oops, something went wrong.