[kbn-es] Allow ES snapshot version mismatch with Kibana (#120942) (#121339)

Co-authored-by: Brian Seeders <brian.seeders@elastic.co>
This commit is contained in:
Kibana Machine 2021-12-15 14:38:11 -05:00 committed by GitHub
parent 777d7e646d
commit 17b76310c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 8 deletions

View file

@ -69,6 +69,18 @@ beforeEach(() => {
valid: {
archives: [createArchive({ license: 'oss' }), createArchive({ license: 'default' })],
},
invalidArch: {
archives: [
createArchive({ license: 'oss', architecture: 'invalid_arch' }),
createArchive({ license: 'default', architecture: 'invalid_arch' }),
],
},
differentVersion: {
archives: [
createArchive({ license: 'oss', version: 'another-version' }),
createArchive({ license: 'default', version: 'another-version' }),
],
},
multipleArch: {
archives: [
createArchive({ architecture: 'fake_arch', license: 'oss' }),
@ -116,8 +128,14 @@ describe('Artifact', () => {
artifactTest('INVALID_LICENSE', 'default')
);
it('should return an artifact even if the version does not match', async () => {
mockFetch(MOCKS.differentVersion);
artifactTest('default', 'default');
});
it('should throw when an artifact cannot be found in the manifest for the specified parameters', async () => {
await expect(Artifact.getSnapshot('default', 'INVALID_VERSION', log)).rejects.toThrow(
mockFetch(MOCKS.invalidArch);
await expect(Artifact.getSnapshot('default', MOCK_VERSION, log)).rejects.toThrow(
"couldn't find an artifact"
);
});
@ -144,8 +162,14 @@ describe('Artifact', () => {
artifactTest('INVALID_LICENSE', 'default', 2)
);
it('should return an artifact even if the version does not match', async () => {
mockFetch(MOCKS.differentVersion);
artifactTest('default', 'default', 2);
});
it('should throw when an artifact cannot be found in the manifest for the specified parameters', async () => {
await expect(Artifact.getSnapshot('default', 'INVALID_VERSION', log)).rejects.toThrow(
mockFetch(MOCKS.invalidArch);
await expect(Artifact.getSnapshot('default', MOCK_VERSION, log)).rejects.toThrow(
"couldn't find an artifact"
);
});

View file

@ -156,16 +156,18 @@ async function getArtifactSpecForSnapshot(
const arch = process.arch === 'arm64' ? 'aarch64' : 'x86_64';
const archive = manifest.archives.find(
(a) =>
a.version === desiredVersion &&
a.platform === platform &&
a.license === desiredLicense &&
a.architecture === arch
(a) => a.platform === platform && a.license === desiredLicense && a.architecture === arch
);
if (!archive) {
throw createCliError(
`Snapshots for ${desiredVersion} are available, but couldn't find an artifact in the manifest for [${desiredVersion}, ${desiredLicense}, ${platform}]`
`Snapshots are available, but couldn't find an artifact in the manifest for [${desiredLicense}, ${platform}, ${arch}]`
);
}
if (archive.version !== desiredVersion) {
log.warning(
`Snapshot found, but version does not match Kibana. Kibana: ${desiredVersion}, Snapshot: ${archive.version}`
);
}