Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't block airgap upload if compatibility couldn't be determined in the UI and handle invalid yaml files #2503

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions web/src/utilities/airgapUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ export class AirgapUploader {

upload = async (processParams, onProgress, onError, onComplete) => {
try {
// first, validate that the release is compatible with the current kots version
const appSpec = await Utilities.getAppSpecFromAirgapBundle(this.resumableFile.file)
const compatibilityResponse = await this.checkKotsVersionCompatibility(appSpec);
// first, validate that the release is compatible with the current kots version.
// don't block the upload process if compatibility couldn't be determined here
// since this is just to fail early and the api will recheck for compatibility later on.
let compatibilityResponse;
try {
const appSpec = await Utilities.getAppSpecFromAirgapBundle(this.resumableFile.file);
compatibilityResponse = await this.checkKotsVersionCompatibility(appSpec);
} catch(err) {
console.log(err);
}
if (compatibilityResponse?.isCompatible === false) {
throw new Error(compatibilityResponse?.error);
}
Expand Down
22 changes: 13 additions & 9 deletions web/src/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,20 @@ export const Utilities = {
buffers.push(buffer);
});
stream.on("end", async () => {
const content = Buffer.concat(buffers).toString("utf-8");
const docs = await yaml.safeLoadAll(content);
for (const doc of docs) {
if (!doc) {
continue;
}
if (doc?.kind === "Application" && doc?.apiVersion === "kots.io/v1beta1") {
resolve(content);
return;
try {
const content = Buffer.concat(buffers).toString("utf-8");
const docs = await yaml.safeLoadAll(content);
for (const doc of docs) {
if (!doc) {
continue;
}
if (doc?.kind === "Application" && doc?.apiVersion === "kots.io/v1beta1") {
resolve(content);
return;
}
}
} catch(_) {
// invalid yaml file, don't stop
}
next();
})
Expand Down