Handle disable at the route level and recreate a new gatekeeper app

so you can re-enable without having to refresh the page

rancher/dashboard#394
This commit is contained in:
Westly Wright 2020-03-27 10:51:34 -07:00
parent b311197552
commit 527a64d99f
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
2 changed files with 56 additions and 10 deletions

View File

@ -1,4 +1,5 @@
<script> <script>
import { isEmpty } from 'lodash';
import CodeMirror from './CodeMirror'; import CodeMirror from './CodeMirror';
import AsyncButton from '@/components/AsyncButton'; import AsyncButton from '@/components/AsyncButton';
import Footer from '@/components/form/Footer'; import Footer from '@/components/form/Footer';
@ -136,14 +137,14 @@ export default {
const gatekeeperStatus = (gatekeeper.status?.conditions || []).slice(); 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 // this doesn't seeem right but the only way I can see to check that it was removed before the object goes away
if (Object.prototype.hasOwnProperty.call(meta, 'deletionTimestamp')) { if (meta && Object.prototype.hasOwnProperty.call(meta, 'deletionTimestamp')) {
this.gatekeeperEnabled = false; this.gatekeeperEnabled = false;
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled); this.$emit('gatekeeperEnabled', this.gatekeeperEnabled);
return; return;
} }
if (gatekeeperStatus.some(app => app.type === 'Deployed')) { if (!this.gatekeeperEnabled && gatekeeperStatus.some(app => app.type === 'Deployed')) {
this.gatekeeperEnabled = true; this.gatekeeperEnabled = true;
this.$emit('gatekeeperEnabled', this.gatekeeperEnabled); this.$emit('gatekeeperEnabled', this.gatekeeperEnabled);
} }

View File

@ -42,7 +42,9 @@ export default {
data() { data() {
return { return {
gateKeeperUnavailable: false, gateKeeperUnavailable: false,
gatekeeperSystemTemplate: null,
mode: _VIEW, mode: _VIEW,
systemProject: null,
}; };
}, },
@ -59,6 +61,8 @@ export default {
return { return {
gateKeeperUnavailable: true, gateKeeperUnavailable: true,
gatekeeperEnabled: false, gatekeeperEnabled: false,
gatekeeperSystemTemplate: null,
systemProject: null,
mode, mode,
}; };
} }
@ -77,6 +81,8 @@ export default {
return { return {
gateKeeperUnAvailable: true, gateKeeperUnAvailable: true,
gatekeeperEnabled: false, gatekeeperEnabled: false,
gatekeeperSystemTemplate: null,
systemProject: null,
mode, mode,
}; };
} }
@ -117,6 +123,8 @@ export default {
return { return {
gatekeeperEnabled: !!gatekeeper?.id, gatekeeperEnabled: !!gatekeeper?.id,
gatekeeperSystemTemplate: template,
systemProject: targetSystemProject,
gatekeeper, gatekeeper,
mode, mode,
namespaces, namespaces,
@ -151,6 +159,43 @@ export default {
} }
next(); next();
}, },
methods: {
async syncGatekeeperStatus(status) {
const gatekeeperVersionsMap = this.gatekeeperSystemTemplate?.spec?.versions || [];
const latestGKVersion = gatekeeperVersionsMap[0] ? gatekeeperVersionsMap[0] : null;
let newApp = null;
this.gatekeeperEnabled = status;
if (!status && latestGKVersion) {
try {
newApp = await this.createGatekeeperDefaultApp(this.systemProject, latestGKVersion.externalId);
this.gatekeeper = newApp;
this.mode = _CREATE;
console.log('New Gatekeeper', this.gatekeeper);
} catch (err) {
console.error('could not create new gatekeeper app', err);
}
}
},
createGatekeeperDefaultApp(systemProject, externalId) {
return this.$store.dispatch('clusterExternal/create', {
type: 'app',
metadata: {
namespace: systemProject.metadata.name,
name: APP_ID
},
spec: {
targetNamespace: 'gatekeeper-system',
timeout: 300,
valuesYaml: CONFIG,
projectName: systemProject.namespacedName,
externalId,
}
});
},
}
}; };
</script> </script>
@ -167,7 +212,7 @@ export default {
:mode="mode" :mode="mode"
:namespaces="namespaces" :namespaces="namespaces"
:projects="projects" :projects="projects"
@gatekeeperEnabled="status => gatekeeperEnabled = status" @gatekeeperEnabled="syncGatekeeperStatus"
/> />
<InfoBox v-if="gatekeeperEnabled"> <InfoBox v-if="gatekeeperEnabled">
<div class="mb-15"> <div class="mb-15">