From 1edfd2a006782b12b349f90ff9f988e1dce2468a Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Fri, 24 Apr 2020 11:09:28 -0700 Subject: [PATCH] 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 --- components/GatekeeperConfig.vue | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/components/GatekeeperConfig.vue b/components/GatekeeperConfig.vue index d3a5122b7c..7b33f11ff2 100644 --- a/components/GatekeeperConfig.vue +++ b/components/GatekeeperConfig.vue @@ -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;