Correctly wait for the gatekeeper app to be ready

app doesn't have a state so all the logic was a little wonky, the state must
have been removed. setup the app to watch for the deployed condition instead.
refactored the logic about sending out the emit a bit too so that the config
observer sends the event only if the wait for contidion call int he enable has
failed. it seems a little bonkers to wait 60 seconds which can happen some
times. 30 second default should be more than enough in most cases so this really
catches outside cases where clusters may be bogged down and slow.

rancher/dashboard#371 - Scenario 2
This commit is contained in:
Westly Wright 2020-04-24 11:09:28 -07:00
parent 52cafa1a58
commit 1edfd2a006
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
1 changed files with 19 additions and 14 deletions

View File

@ -134,19 +134,20 @@ export default {
handler() {
const gatekeeper = this.config || {};
const meta = gatekeeper?.metadata;
const gatekeeperStatus = (gatekeeper.status?.conditions || []).slice();
// this doesn't seeem right but the only way I can see to check that it was removed before the object goes away
// TODO - perhaps the way to solve this is to fall into this branch, then watch the namespace for delete?
if (meta && Object.prototype.hasOwnProperty.call(meta, 'deletionTimestamp')) {
this.gatekeeperEnabled = false;
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled);
return;
}
if (!this.gatekeeperEnabled && gatekeeperStatus.some(app => app.type === 'Deployed')) {
this.gatekeeperEnabled = true;
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled);
if (!this.gatekeeperEnabled && this.saving && gatekeeper.hasCondition('Deployed', 'True')) { // we can get here if waitForCondition takes too long
if (this.showYamlEditor) {
this.showYamlEditor = false;
}
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled = true);
}
}
}
@ -189,20 +190,24 @@ export default {
this.saving = true;
await this.ensureNamespace();
await this.config.save();
await this.config.waitForState('active', 60000);
this.gatekeeperEnabled = true;
await this.config.waitForCondition('Deployed');
this.showYamlEditor = false;
this.saving = false;
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled = true);
buttonCb(true);
} catch (err) {
this.gatekeeperEnabled = false;
this.saving = false;
if (err?.message) {
this.errors = [err.message];
if (this?.config.hasCondition('Deployed', 'True')) { // we can hit this if waitForCondition above fails, in that case the config observer will enable
buttonCb(true); // dont want to see red button error in this case
} else {
this.errors = [err];
this.gatekeeperEnabled = false;
this.saving = false;
if (err?.message) {
this.errors = [err.message];
} else {
this.errors = [err];
}
buttonCb(false);
}
buttonCb(false);
}
this.saving = false;