From cd7752ec5cef45f11cc0fdcd5f36aea426ca3683 Mon Sep 17 00:00:00 2001 From: "Md. Samiul Haque" Date: Fri, 20 Dec 2024 10:36:25 +0600 Subject: [PATCH] add storageclass dependency on archiver switch in db create forms (#697) Signed-off-by: samiul --- .../ui/create-ui.yaml | 13 ++- .../ui/functions.js | 97 ++++++++++++++++--- .../ui/create-ui.yaml | 11 ++- .../ui/functions.js | 97 ++++++++++++++++--- .../ui/create-ui.yaml | 11 ++- .../ui/functions.js | 97 ++++++++++++++++--- .../ui/create-ui.yaml | 11 ++- .../ui/functions.js | 97 ++++++++++++++++--- .../ui/create-ui.yaml | 11 ++- .../ui/functions.js | 97 ++++++++++++++++--- 10 files changed, 471 insertions(+), 71 deletions(-) diff --git a/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml index 87adb2634..d5a0b5474 100644 --- a/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml @@ -313,12 +313,21 @@ steps: $ref: discriminator#/properties/backup type: switch - elements: - - label: + - disabled: showArchiverAlert + label: text: Enable Archiver? + onChange: onArchiverChange schema: $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch - if: isToggleOn|archiver + - label: + text: The selected StorageClass does not support Archiver + alertInfo: + type: info + show: true + if: showArchiverAlert + type: label-element + if: showArchiver type: single-step-form - elements: - label: diff --git a/charts/kubedbcom-mariadb-editor-options/ui/functions.js b/charts/kubedbcom-mariadb-editor-options/ui/functions.js index e2c2088a8..fcdd63afe 100644 --- a/charts/kubedbcom-mariadb-editor-options/ui/functions.js +++ b/charts/kubedbcom-mariadb-editor-options/ui/functions.js @@ -765,7 +765,10 @@ function fetchOptions({ model, getValue }, type) { return [] } -function getAdminOptions({ getValue, model, watchDependency }, type) { +let archiverMap = [] +let archiverCalled = false + +function getAdminOptions({ getValue, model, watchDependency, axios, storeGet }, type) { watchDependency('discriminator#/bundleApiLoaded') const options = getValue(model, `/spec/admin/${type}/available`) || [] @@ -782,9 +785,83 @@ function getAdminOptions({ getValue, model, watchDependency }, type) { })) || [] ) } + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName({ axios, storeGet }, options) + } return options } +function showArchiver({ watchDependency, getValue, model, commit }) { + watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn({ getValue, model }, 'archiver') +} + +async function getArchiverName({ axios, storeGet }, options) { + try { + archiverCalled = true + const params = storeGet('/route/params') + const { user, cluster, group, resource } = params + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses` + const resp = await axios.get(url) + + resp.data?.items?.forEach((item) => { + const annotations = item.metadata?.annotations + const classname = item.metadata?.name + const annotationKeyToFind = `${resource}.${group}/archiver` + archiverMap.push({ storageClass: classname, annotation: annotations[annotationKeyToFind] }) + return resp.data + }) + } catch (e) { + console.log(e) + } +} + +function onArchiverChange({ model, getValue, commit }) { + const isArchiverOn = getValue(model, '/spec/admin/archiver/enable/default') + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) +} + +function showArchiverAlert({ watchDependency, model, getValue, commit }) { + watchDependency('model#/spec/admin/storageClasses/default') + + watchDependency('model#/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + + // toggle archiver to false when storageClass annotation not found + if (show) + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + + return show +} + function checkIfFeatureOn({ getValue, model }, type) { let val = getValue(model, `/spec/admin/${type}/toggle`) if (type === 'backup' || type === 'archiver') { @@ -801,25 +878,16 @@ function checkIfFeatureOn({ getValue, model }, type) { } else if (type === 'monitoring') { return features.includes('monitoring') && val } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + return features.includes('backup') && val } } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { +function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { watchDependency('discriminator#/bundleApiLoaded') watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/mode') const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') let deploymentType = getValue(model, `/spec/admin/deployment/default`) - const mode = getValue(model, '/spec/mode') - if (type === 'archiver' && mode === 'Standalone') return false - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { return checkIfFeatureOn({ getValue, model }, type) } else if ( type === 'clusterTier' || @@ -1161,4 +1229,7 @@ return { setBackup, showAdditionalSettings, getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, } diff --git a/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml index 7a4bcc942..dd17ac373 100644 --- a/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml @@ -546,12 +546,21 @@ steps: $ref: discriminator#/backup type: switch - elements: - - if: isToggleOn|archiver + - disabled: showArchiverAlert label: text: Enable Archiver? + onChange: onArchiverChange schema: $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch + - label: + text: The selected StorageClass does not support Archiver + alertInfo: + type: info + show: true + if: showArchiverAlert + type: label-element + if: showArchiver type: single-step-form - elements: - if: isToggleOn|tls diff --git a/charts/kubedbcom-mongodb-editor-options/ui/functions.js b/charts/kubedbcom-mongodb-editor-options/ui/functions.js index 8eda856a1..ad896216b 100644 --- a/charts/kubedbcom-mongodb-editor-options/ui/functions.js +++ b/charts/kubedbcom-mongodb-editor-options/ui/functions.js @@ -861,7 +861,10 @@ function fetchOptions({ model, getValue }, type) { return [] } -function getAdminOptions({ getValue, model, watchDependency }, type) { +let archiverMap = [] +let archiverCalled = false + +function getAdminOptions({ getValue, model, watchDependency, axios, storeGet }, type) { watchDependency('discriminator#/bundleApiLoaded') const options = getValue(model, `/spec/admin/${type}/available`) || [] @@ -878,9 +881,83 @@ function getAdminOptions({ getValue, model, watchDependency }, type) { })) || [] ) } + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName({ axios, storeGet }, options) + } return options } +function showArchiver({ watchDependency, getValue, model, commit }) { + watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn({ getValue, model }, 'archiver') +} + +async function getArchiverName({ axios, storeGet }, options) { + try { + archiverCalled = true + const params = storeGet('/route/params') + const { user, cluster, group, resource } = params + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses` + const resp = await axios.get(url) + + resp.data?.items?.forEach((item) => { + const annotations = item.metadata?.annotations + const classname = item.metadata?.name + const annotationKeyToFind = `${resource}.${group}/archiver` + archiverMap.push({ storageClass: classname, annotation: annotations[annotationKeyToFind] }) + return resp.data + }) + } catch (e) { + console.log(e) + } +} + +function onArchiverChange({ model, getValue, commit }) { + const isArchiverOn = getValue(model, '/spec/admin/archiver/enable/default') + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) +} + +function showArchiverAlert({ watchDependency, model, getValue, commit }) { + watchDependency('model#/spec/admin/storageClasses/default') + + watchDependency('model#/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + + // toggle archiver to false when storageClass annotation not found + if (show) + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + + return show +} + async function getRecoveryNames({ getValue, model, watchDependency, storeGet, axios }, type) { watchDependency(`model#/spec/init/archiver/${type}/namespace`) const params = storeGet('/route/params') @@ -920,25 +997,16 @@ function checkIfFeatureOn({ getValue, model }, type) { } else if (type === 'monitoring') { return features.includes('monitoring') && val } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + return features.includes('backup') && val } } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { +function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { watchDependency('discriminator#/bundleApiLoaded') watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/mode') const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') let deploymentType = getValue(model, `/spec/admin/deployment/default`) - const mode = getValue(model, '/spec/mode') - if (type === 'archiver' && mode === 'Standalone') return false - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { return checkIfFeatureOn({ getValue, model }, type) } else if ( type === 'clusterTier' || @@ -1288,4 +1356,7 @@ return { onAuthChange, setBackup, getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, } diff --git a/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml index 9dd5cbdc5..413b7a1fa 100644 --- a/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml @@ -348,12 +348,21 @@ steps: $ref: discriminator#/backup type: switch - elements: - - if: isToggleOn|archiver + - disabled: showArchiverAlert label: text: Enable Archiver? + onChange: onArchiverChange schema: $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch + - label: + text: The selected StorageClass does not support Archiver + alertInfo: + type: info + show: true + if: showArchiverAlert + type: label-element + if: showArchiver type: single-step-form - if: isToggleOn|tls label: diff --git a/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js b/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js index ac9c2394d..67c0ebbe8 100644 --- a/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js +++ b/charts/kubedbcom-mssqlserver-editor-options/ui/functions.js @@ -844,7 +844,10 @@ function fetchOptions({ model, getValue }, type) { return [] } -function getAdminOptions({ getValue, model, watchDependency }, type) { +let archiverMap = [] +let archiverCalled = false + +function getAdminOptions({ getValue, model, watchDependency, axios, storeGet }, type) { watchDependency('discriminator#/bundleApiLoaded') const options = getValue(model, `/spec/admin/${type}/available`) || [] @@ -861,9 +864,83 @@ function getAdminOptions({ getValue, model, watchDependency }, type) { })) || [] ) } + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName({ axios, storeGet }, options) + } return options } +function showArchiver({ watchDependency, getValue, model, commit }) { + watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn({ getValue, model }, 'archiver') +} + +async function getArchiverName({ axios, storeGet }, options) { + try { + archiverCalled = true + const params = storeGet('/route/params') + const { user, cluster, group, resource } = params + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses` + const resp = await axios.get(url) + + resp.data?.items?.forEach((item) => { + const annotations = item.metadata?.annotations + const classname = item.metadata?.name + const annotationKeyToFind = `${resource}.${group}/archiver` + archiverMap.push({ storageClass: classname, annotation: annotations[annotationKeyToFind] }) + return resp.data + }) + } catch (e) { + console.log(e) + } +} + +function onArchiverChange({ model, getValue, commit }) { + const isArchiverOn = getValue(model, '/spec/admin/archiver/enable/default') + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) +} + +function showArchiverAlert({ watchDependency, model, getValue, commit }) { + watchDependency('model#/spec/admin/storageClasses/default') + + watchDependency('model#/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + + // toggle archiver to false when storageClass annotation not found + if (show) + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + + return show +} + function checkIfFeatureOn({ getValue, model }, type) { let val = getValue(model, `/spec/admin/${type}/toggle`) if (type === 'backup' || type === 'archiver') { @@ -880,25 +957,16 @@ function checkIfFeatureOn({ getValue, model }, type) { } else if (type === 'monitoring') { return features.includes('monitoring') && val } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + return features.includes('backup') && val } } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { +function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { watchDependency('discriminator#/bundleApiLoaded') watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/mode') const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') let deploymentType = getValue(model, `/spec/admin/deployment/default`) - const mode = getValue(model, '/spec/mode') - if (type === 'archiver' && mode === 'Standalone') return false - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { return checkIfFeatureOn({ getValue, model }, type) } else if ( type === 'clusterTier' || @@ -1197,4 +1265,7 @@ return { onPidChange, isPidCustom, onCustomPidChange, + onArchiverChange, + showArchiverAlert, + showArchiver, } diff --git a/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml b/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml index 3bf29dbfe..26a01a385 100644 --- a/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-mysql-editor-options/ui/create-ui.yaml @@ -328,12 +328,21 @@ steps: $ref: discriminator#/backup type: switch - elements: - - if: isToggleOn|archiver + - disabled: showArchiverAlert label: text: Enable Archiver? + onChange: onArchiverChange schema: $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch + - label: + text: The selected StorageClass does not support Archiver + alertInfo: + type: info + show: true + if: showArchiverAlert + type: label-element + if: showArchiver type: single-step-form - elements: - if: isToggleOn|tls diff --git a/charts/kubedbcom-mysql-editor-options/ui/functions.js b/charts/kubedbcom-mysql-editor-options/ui/functions.js index e93a48e13..b9a8fbbc6 100644 --- a/charts/kubedbcom-mysql-editor-options/ui/functions.js +++ b/charts/kubedbcom-mysql-editor-options/ui/functions.js @@ -769,7 +769,10 @@ function fetchOptions({ model, getValue }, type) { return [] } -function getAdminOptions({ getValue, model, watchDependency }, type) { +let archiverMap = [] +let archiverCalled = false + +function getAdminOptions({ getValue, model, watchDependency, axios, storeGet }, type) { watchDependency('discriminator#/bundleApiLoaded') const options = getValue(model, `/spec/admin/${type}/available`) || [] @@ -786,9 +789,83 @@ function getAdminOptions({ getValue, model, watchDependency }, type) { })) || [] ) } + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName({ axios, storeGet }, options) + } return options } +function showArchiver({ watchDependency, getValue, model, commit }) { + watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn({ getValue, model }, 'archiver') +} + +async function getArchiverName({ axios, storeGet }, options) { + try { + archiverCalled = true + const params = storeGet('/route/params') + const { user, cluster, group, resource } = params + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses` + const resp = await axios.get(url) + + resp.data?.items?.forEach((item) => { + const annotations = item.metadata?.annotations + const classname = item.metadata?.name + const annotationKeyToFind = `${resource}.${group}/archiver` + archiverMap.push({ storageClass: classname, annotation: annotations[annotationKeyToFind] }) + return resp.data + }) + } catch (e) { + console.log(e) + } +} + +function onArchiverChange({ model, getValue, commit }) { + const isArchiverOn = getValue(model, '/spec/admin/archiver/enable/default') + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) +} + +function showArchiverAlert({ watchDependency, model, getValue, commit }) { + watchDependency('model#/spec/admin/storageClasses/default') + + watchDependency('model#/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + + // toggle archiver to false when storageClass annotation not found + if (show) + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + + return show +} + function checkIfFeatureOn({ getValue, model }, type) { let val = getValue(model, `/spec/admin/${type}/toggle`) if (type === 'backup' || type === 'archiver') { @@ -805,25 +882,16 @@ function checkIfFeatureOn({ getValue, model }, type) { } else if (type === 'monitoring') { return features.includes('monitoring') && val } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + return features.includes('backup') && val } } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { +function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { watchDependency('discriminator#/bundleApiLoaded') watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/mode') const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') let deploymentType = getValue(model, `/spec/admin/deployment/default`) - const mode = getValue(model, '/spec/mode') - if (type === 'archiver' && mode === 'Standalone') return false - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { return checkIfFeatureOn({ getValue, model }, type) } else if ( type === 'clusterTier' || @@ -1158,4 +1226,7 @@ return { clearConfiguration, setBackup, getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, } diff --git a/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml b/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml index cd247c557..fd577fb54 100644 --- a/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-postgres-editor-options/ui/create-ui.yaml @@ -317,12 +317,21 @@ steps: $ref: discriminator#/backup type: switch - elements: - - if: isToggleOn|archiver + - disabled: showArchiverAlert label: text: Enable Archiver? + onChange: onArchiverChange schema: $ref: schema#/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default type: switch + - label: + text: The selected StorageClass does not support Archiver + alertInfo: + type: info + show: true + if: showArchiverAlert + type: label-element + if: showArchiver type: single-step-form - elements: - if: isToggleOn|tls diff --git a/charts/kubedbcom-postgres-editor-options/ui/functions.js b/charts/kubedbcom-postgres-editor-options/ui/functions.js index d9f653a5c..0079d6859 100644 --- a/charts/kubedbcom-postgres-editor-options/ui/functions.js +++ b/charts/kubedbcom-postgres-editor-options/ui/functions.js @@ -937,7 +937,10 @@ function fetchOptions({ model, getValue }, type) { return [] } -function getAdminOptions({ getValue, model, watchDependency }, type) { +let archiverMap = [] +let archiverCalled = false + +function getAdminOptions({ getValue, model, watchDependency, axios, storeGet }, type) { watchDependency('discriminator#/bundleApiLoaded') const options = getValue(model, `/spec/admin/${type}/available`) || [] @@ -953,9 +956,83 @@ function getAdminOptions({ getValue, model, watchDependency }, type) { })) || [] ) } + if (type === 'storageClasses' && !archiverCalled) { + getArchiverName({ axios, storeGet }, options) + } return options } +function showArchiver({ watchDependency, getValue, model, commit }) { + watchDependency('model#/spec/mode') + const dbmode = getValue(model, '/spec/mode') + + if (dbmode === 'Standalone') { + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + return false + } + return checkIfFeatureOn({ getValue, model }, 'archiver') +} + +async function getArchiverName({ axios, storeGet }, options) { + try { + archiverCalled = true + const params = storeGet('/route/params') + const { user, cluster, group, resource } = params + const url = `/clusters/${user}/${cluster}/proxy/storage.k8s.io/v1/storageclasses` + const resp = await axios.get(url) + + resp.data?.items?.forEach((item) => { + const annotations = item.metadata?.annotations + const classname = item.metadata?.name + const annotationKeyToFind = `${resource}.${group}/archiver` + archiverMap.push({ storageClass: classname, annotation: annotations[annotationKeyToFind] }) + return resp.data + }) + } catch (e) { + console.log(e) + } +} + +function onArchiverChange({ model, getValue, commit }) { + const isArchiverOn = getValue(model, '/spec/admin/archiver/enable/default') + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + + if (isArchiverOn && found?.annotation) + commit('wizard/model$update', { + path: '/spec/archiverName', + value: found.annotation, + force: true, + }) +} + +function showArchiverAlert({ watchDependency, model, getValue, commit }) { + watchDependency('model#/spec/admin/storageClasses/default') + + watchDependency('model#/spec/mode') + const mode = getValue(model, '/spec/mode') + if (mode === 'Standalone') return false + + const stClass = getValue(model, '/spec/admin/storageClasses/default') + const found = archiverMap.find((item) => item.storageClass === stClass) + const show = !found?.annotation + + // toggle archiver to false when storageClass annotation not found + if (show) + commit('wizard/model$update', { + path: '/spec/admin/archiver/enable/default', + value: false, + force: true, + }) + + return show +} + function checkIfFeatureOn({ getValue, model }, type) { let val = getValue(model, `/spec/admin/${type}/toggle`) if (type === 'backup' || type === 'archiver') { @@ -972,25 +1049,16 @@ function checkIfFeatureOn({ getValue, model }, type) { } else if (type === 'monitoring') { return features.includes('monitoring') && val } else if (type === 'archiver') { - return features.includes('backup') && backupVal === 'KubeStash' && val + return features.includes('backup') && val } } -function isToggleOn({ getValue, model, discriminator, watchDependency }, type) { +function isToggleOn({ getValue, model, discriminator, watchDependency, commit }, type) { watchDependency('discriminator#/bundleApiLoaded') watchDependency('model#/spec/admin/deployment/default') - watchDependency('model#/spec/mode') const bundleApiLoaded = getValue(discriminator, '/bundleApiLoaded') let deploymentType = getValue(model, `/spec/admin/deployment/default`) - const mode = getValue(model, '/spec/mode') - if (type === 'archiver' && mode === 'Standalone') return false - if ( - type === 'tls' || - type === 'backup' || - type === 'expose' || - type === 'monitoring' || - type === 'archiver' - ) { + if (type === 'tls' || type === 'backup' || type === 'expose' || type === 'monitoring') { return checkIfFeatureOn({ getValue, model }, type) } else if ( type === 'clusterTier' || @@ -1368,4 +1436,7 @@ return { setBackup, showAdditionalSettings, getDefault, + onArchiverChange, + showArchiverAlert, + showArchiver, }