Skip to content

Commit

Permalink
[8.12][Fleet] add kibana version if air gapped or product versions do…
Browse files Browse the repository at this point in the history
…esn't … (#175189)

Backport #174324 to 8.12
  • Loading branch information
juliaElastic authored Jan 22, 2024
1 parent 519fbb8 commit 0485400
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/services/agents/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('getAvailableVersions', () => {
});

it('should cache results', async () => {
mockKibanaVersion = '300.0.0';
mockKibanaVersion = '9.0.0';
mockedReadFile.mockResolvedValue(`["8.1.0", "8.0.0", "7.17.0", "7.16.0"]`);
mockedFetch.mockResolvedValueOnce({
status: 200,
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('getAvailableVersions', () => {
const res = await getAvailableVersions({ ignoreCache: true });

// Should sort, uniquify and filter out versions < 7.17
expect(res).toEqual(['8.1.0', '8.0.0', '7.17.0']);
expect(res).toEqual(['300.0.0', '8.1.0', '8.0.0', '7.17.0']);
});

it('should gracefully handle network errors when fetching from product versions API', async () => {
Expand All @@ -202,6 +202,6 @@ describe('getAvailableVersions', () => {
const res = await getAvailableVersions({ ignoreCache: true });

// Should sort, uniquify and filter out versions < 7.17
expect(res).toEqual(['8.1.0', '8.0.0', '7.17.0']);
expect(res).toEqual(['300.0.0', '8.1.0', '8.0.0', '7.17.0']);
});
});
11 changes: 6 additions & 5 deletions x-pack/plugins/fleet/server/services/agents/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ export const getAvailableVersions = async ({
.filter((v: any) => semverGte(v, MINIMUM_SUPPORTED_VERSION))
.sort((a: any, b: any) => (semverGt(a, b) ? -1 : 1));

// If the current stack version isn't included in the list of available versions, add it
// at the front of the array
const hasCurrentVersion = availableVersions.some((v) => v === kibanaVersion);
if (includeCurrentVersion && !hasCurrentVersion) {
availableVersions = [kibanaVersion, ...availableVersions];
// if api versions are empty (air gapped or API not available), we add current kibana version, as the build file might not contain the latest released version
if (
includeCurrentVersion ||
(apiVersions.length === 0 && !config?.internal?.onlyAllowAgentUpgradeToKnownVersions)
) {
availableVersions = uniq([kibanaVersion, ...availableVersions]);
}

// Allow upgrading to the current stack version if this override flag is provided via `kibana.yml`.
Expand Down

0 comments on commit 0485400

Please sign in to comment.