Skip to content

Commit 18ccb23

Browse files
authored
improve backupsession & restoresession fields
* filter invoker Signed-off-by: Samiul <samiul@appscode.com> * filter restore fields for restoresession --------- Signed-off-by: Samiul <samiul@appscode.com>
1 parent c62144a commit 18ccb23

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

charts/corekubestashcom-backupsession-editor-options/ui/functions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ export const useFunc = (model) => {
9191
const url = `/clusters/${user}/${cluster}/proxy/${core}/${version}/namespaces/${namespace}/${suffix}`
9292
const resp = await axios.get(url)
9393
invokerData = resp.data.items
94-
const names = resp.data.items.map((item) => {
94+
95+
const dbKind = storeGet('/resource/layout/result/resource/kind') || ''
96+
const group = storeGet('/resource/layout/result/resource/group') || ''
97+
if (group === 'kubedb.com')
98+
invokerData = invokerData.filter((item) => item.spec?.target?.kind === dbKind)
99+
100+
const names = invokerData.map((item) => {
95101
const name = item.metadata?.name
96102
return name
97103
})

charts/corekubestashcom-restoresession-editor-options/ui/create-ui.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ step:
3939
validation:
4040
type: required
4141
loader: getRepositories
42+
watcher:
43+
func: onRepoChange
44+
paths:
45+
- temp/properties/repository
4246
- type: select
4347
disableUnselect: true
4448
label: Snapshot
@@ -50,9 +54,9 @@ step:
5054
watchPaths:
5155
- temp/properties/repository
5256
watcher:
53-
func: onRepoChange
57+
func: onSnapChange
5458
paths:
55-
- temp/properties/repository
59+
- schema/properties/spec/properties/dataSource/properties/snapshot
5660
- type: select
5761
label: Addon Name
5862
subtitle: Select the restore addon to use
@@ -61,7 +65,14 @@ step:
6165
if:
6266
type: function
6367
name: isConsole
64-
loader: getAddons
68+
loader:
69+
name: getAddons
70+
watchPaths:
71+
- schema/properties/spec/properties/dataSource/properties/snapshot
72+
watcher:
73+
func: clearAddon
74+
paths:
75+
- schema/properties/spec/properties/dataSource/properties/snapshot
6576
- type: textarea
6677
label: Additional Parameters
6778
schema: temp/properties/params
@@ -71,7 +82,6 @@ step:
7182
- temp/properties/params
7283
- type: block-layout
7384
showLabels: true
74-
hideBlock: true
7585
label: Restore Target
7686
if:
7787
type: function
@@ -85,6 +95,9 @@ step:
8595
subtitle: Select the API group of the target resource (e.g., apps, kubedb.com)
8696
schema: schema/properties/spec/properties/target/properties/apiGroup
8797
loader: getApiGroup
98+
if:
99+
name: showGroupKind
100+
type: function
88101
- type: select
89102
label: Kind
90103
subtitle: Select the resource type (e.g., Deployment, StatefulSet, MongoDB, PostgreSQL)
@@ -93,11 +106,15 @@ step:
93106
name: getKinds
94107
watchPaths:
95108
- schema/properties/spec/properties/target/properties/apiGroup
109+
- schema/properties/spec/properties/dataSource/properties/snapshot
96110
watcher:
97111
func: setVersion
98112
paths:
99113
- schema/properties/spec/properties/target/properties/kind
100114
- schema/properties/spec/properties/target/properties/apiGroup
115+
if:
116+
name: showGroupKind
117+
type: function
101118
- type: select
102119
label: Namespace
103120
subtitle: Select the namespace where the target resource exists

charts/corekubestashcom-restoresession-editor-options/ui/functions.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ export const useFunc = (model) => {
234234
})
235235
}
236236

237+
let snapshotObj = {}
238+
let snapshotList = []
239+
let snapshotGroup = ''
240+
let snapshotKind = ''
241+
242+
function onSnapChange() {
243+
const snapshot = getValue(model, '/spec/dataSource/snapshot') || ''
244+
snapshotObj = snapshotList.find((item) => item.metadata?.name === snapshot) || {}
245+
snapshotKind = snapshotObj?.spec?.appRef?.kind || ''
246+
snapshotGroup = snapshotObj?.spec?.appRef?.apiGroup || ''
247+
}
248+
237249
async function getSnapshots() {
238250
// watchDependency('discriminator#/repository')
239251
const user = storeGet('/route/params/user') || ''
@@ -250,6 +262,7 @@ export const useFunc = (model) => {
250262
if (namespace) {
251263
const resp = await axios.get(url)
252264
let snapshots = resp?.data?.items
265+
snapshotList = snapshots
253266
snapshots.map((item) => {
254267
const name = item?.metadata?.name
255268
item.value = name
@@ -299,6 +312,14 @@ export const useFunc = (model) => {
299312
return ` ${timeDiff} ago`
300313
}
301314

315+
function showGroupKind() {
316+
const snapshot = getValue(model, '/spec/dataSource/snapshot') || ''
317+
snapshotObj = snapshotList.find((item) => item.metadata?.name === snapshot) || {}
318+
snapshotGroup = snapshotObj?.spec?.appRef?.apiGroup || ''
319+
snapshotKind = snapshotObj?.spec?.appRef?.kind || ''
320+
return !(snapshotGroup === 'kubedb.com')
321+
}
322+
302323
async function getAddons() {
303324
const user = storeGet('/route/params/user') || ''
304325
const cluster = storeGet('/route/params/cluster') || ''
@@ -320,6 +341,28 @@ export const useFunc = (model) => {
320341
force: true,
321342
})
322343
}
344+
if (Object.keys(snapshotObj).length) {
345+
const filteredAddon = addons.find((item) => {
346+
return item.includes(snapshotKind.toLowerCase())
347+
})
348+
349+
if (snapshotGroup === 'kubedb.com') {
350+
commit('wizard/model$update', {
351+
path: '/spec/target/kind',
352+
value: snapshotKind,
353+
force: true,
354+
})
355+
commit('wizard/model$update', {
356+
path: '/spec/target/apiGroup',
357+
value: snapshotGroup,
358+
force: true,
359+
})
360+
setVersion()
361+
}
362+
363+
if (filteredAddon) return [filteredAddon]
364+
}
365+
323366
return addons
324367
} catch (e) {
325368
console.log(e)
@@ -467,7 +510,6 @@ export const useFunc = (model) => {
467510
function getKinds() {
468511
// watchDependency(`model#/spec/target/apiGroup`)
469512
const apiGroup = getValue(model, `/spec/target/apiGroup`)
470-
471513
if (apiGroup === 'core') return coreKind
472514
else if (apiGroup === 'apps') return appKind
473515
else return kubedbKind
@@ -520,6 +562,10 @@ export const useFunc = (model) => {
520562
})
521563
}
522564

565+
function clearAddon() {
566+
return ''
567+
}
568+
523569
return {
524570
isRancherManaged,
525571
fetchNamespaces,
@@ -538,11 +584,14 @@ export const useFunc = (model) => {
538584
getRepositories,
539585
onRepoChange,
540586
getSnapshots,
587+
onSnapChange,
541588
getAddons,
542589
getTasks,
543590
databaseSelected,
544591
returnFalse,
545592
onParameterChange,
546593
setSecurityContext,
594+
showGroupKind,
595+
clearAddon,
547596
}
548597
}

0 commit comments

Comments
 (0)