From 34a19435740eb4ec0f9232d667d769666eb59b2f Mon Sep 17 00:00:00 2001 From: Alexandre Alves Date: Mon, 26 Feb 2024 17:34:32 +0000 Subject: [PATCH] prevent deletion inventory of machines if AdoptionReady === True --- .../elemental.cattle.io.machineinventory.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/elemental/models/elemental.cattle.io.machineinventory.js b/pkg/elemental/models/elemental.cattle.io.machineinventory.js index b3e4dd0..ab0df42 100644 --- a/pkg/elemental/models/elemental.cattle.io.machineinventory.js +++ b/pkg/elemental/models/elemental.cattle.io.machineinventory.js @@ -23,6 +23,14 @@ export default class MachineInventory extends ElementalResource { get _availableActions() { const out = super._availableActions; + if (this.cannotBeDeletedByUi) { + const i = out.findIndex(act => act.action === 'promptRemove'); + + if (i >= 0) { + out.splice(i, 1); + } + } + if (this.canCreateCluster) { out.push({ action: 'createCluster', @@ -97,4 +105,14 @@ export default class MachineInventory extends ElementalResource { return this.$rootGetters['i18n/t']('resourceTable.groupLabel.notInACluster'); } } + + get cannotBeDeletedByUi() { + let cannotBeDeletedByUi = false; + + if (this.status?.conditions && this.status?.conditions.find(c => c.type === 'AdoptionReady' && c.status === 'True')) { + cannotBeDeletedByUi = true; + } + + return cannotBeDeletedByUi; + } }