Skip to content

Commit

Permalink
add storageclass dependency on archiver switch in db create forms (#697)
Browse files Browse the repository at this point in the history
Signed-off-by: samiul <[email protected]>
  • Loading branch information
SamiulSourav authored Dec 20, 2024
1 parent d45f6c5 commit cd7752e
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 71 deletions.
13 changes: 11 additions & 2 deletions charts/kubedbcom-mariadb-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
97 changes: 84 additions & 13 deletions charts/kubedbcom-mariadb-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`) || []
Expand All @@ -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') {
Expand All @@ -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' ||
Expand Down Expand Up @@ -1161,4 +1229,7 @@ return {
setBackup,
showAdditionalSettings,
getDefault,
onArchiverChange,
showArchiverAlert,
showArchiver,
}
11 changes: 10 additions & 1 deletion charts/kubedbcom-mongodb-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
97 changes: 84 additions & 13 deletions charts/kubedbcom-mongodb-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`) || []
Expand All @@ -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')
Expand Down Expand Up @@ -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' ||
Expand Down Expand Up @@ -1288,4 +1356,7 @@ return {
onAuthChange,
setBackup,
getDefault,
onArchiverChange,
showArchiverAlert,
showArchiver,
}
11 changes: 10 additions & 1 deletion charts/kubedbcom-mssqlserver-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit cd7752e

Please sign in to comment.