Skip to content

Commit d2bcba8

Browse files
committed
add archiver fields to clickhouse
Signed-off-by: samiul <samiul@appscode.com>
1 parent 4b1ab13 commit d2bcba8

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,57 @@ step:
301301
label: Configuration
302302
schema: schema/properties/spec/properties/configuration
303303
type: textarea
304+
- if:
305+
name: isToggleOn|pointInTimeRecovery
306+
type: function
307+
init:
308+
type: func
309+
value: getDefault|pointInTimeRecovery
310+
label: Point in-time Recovery?
311+
schema: temp/recovery
312+
type: switch
313+
- elements:
314+
- label: ""
315+
subtitle: Configure point-in-time recovery to restore your database to a specific
316+
moment. Specify the source database namespace, name, and the exact timestamp
317+
for recovery.
318+
type: label-element
319+
- elements:
320+
- forceRequired: true
321+
label: Namespace
322+
schema: temp/refNamespace
323+
type: input
324+
validation:
325+
type: required
326+
watcher:
327+
func: setPointInTimeRecovery
328+
paths:
329+
- temp/refNamespace
330+
- label: Name
331+
schema: temp/refDBName
332+
type: input
333+
validation:
334+
type: required
335+
watcher:
336+
func: setPointInTimeRecovery
337+
paths:
338+
- temp/refDBName
339+
showLabels: true
340+
type: horizontal-layout
341+
- customClass: mt-10
342+
label: Recovery Timestamp
343+
schema: schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp
344+
type: date-time
345+
watcher:
346+
func: onTimestampChange
347+
paths:
348+
- schema/properties/spec/properties/init/properties/archiver/properties/recoveryTimestamp
349+
if:
350+
name: showRecovery
351+
type: function
352+
label: Point in-time Recovery
353+
showLabels: true
354+
type: block-layout
304355
- if:
305356
name: isToggleOn|deployment
306357
type: function
@@ -377,6 +428,28 @@ step:
377428
func: onBackupSwitch
378429
paths:
379430
- temp/backup
431+
- elements:
432+
- disable:
433+
name: showArchiverAlert
434+
watchPaths:
435+
- schema/spec/admin/storageClasses/default
436+
- schema/spec/mode
437+
label: Enable Archiver?
438+
schema: schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default
439+
type: switch
440+
watcher:
441+
func: onArchiverChange
442+
paths:
443+
- schema/properties/spec/properties/admin/properties/archiver/properties/enable/properties/default
444+
- if:
445+
name: showArchiverAlert
446+
type: function
447+
label: The selected StorageClass does not support Archiver
448+
type: warning
449+
if:
450+
name: showArchiver
451+
type: function
452+
type: block-layout
380453
- elements:
381454
- if:
382455
name: isToggleOn|tls

charts/kubedbcom-clickhouse-editor-options/ui/functions.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,121 @@ export const useFunc = (model) => {
13081308
return (val && expected === 'true') || (!val && expected === 'false')
13091309
}
13101310

1311+
function showRecovery() {
1312+
// watchDependency('discriminator#/recovery')
1313+
const isRecoveryOn = getValue(discriminator, '/recovery') || ''
1314+
return isRecoveryOn
1315+
}
1316+
1317+
async function setPointInTimeRecovery() {
1318+
const owner = storeGet('/route/params/user')
1319+
const cluster = storeGet('/route/params/cluster')
1320+
const refNamespace = getValue(discriminator, '/refNamespace')
1321+
const refDBName = getValue(discriminator, '/refDBName')
1322+
1323+
try {
1324+
const repositoriesUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/repositories/${refDBName}-full`
1325+
const snapshotsUrl = `clusters/${owner}/${cluster}/proxy/storage.kubestash.com/v1alpha1/namespaces/${refNamespace}/snapshots/${refDBName}-incremental-snapshot`
1326+
const repositoriesResp = await axios.get(repositoriesUrl)
1327+
const snapshotsResp = await axios.get(snapshotsUrl)
1328+
1329+
commit('wizard/model$update', {
1330+
path: `/spec/init/archiver/encryptionSecret/name`,
1331+
value: repositoriesResp.data?.spec.encryptionSecret.name,
1332+
force: true,
1333+
})
1334+
commit('wizard/model$update', {
1335+
path: `/spec/init/archiver/encryptionSecret/namespace`,
1336+
value: repositoriesResp.data?.spec.encryptionSecret.namespace,
1337+
force: true,
1338+
})
1339+
commit('wizard/model$update', {
1340+
path: `/spec/init/archiver/fullDBRepository/name`,
1341+
value: `${refDBName}-full`,
1342+
force: true,
1343+
})
1344+
commit('wizard/model$update', {
1345+
path: `/spec/init/archiver/fullDBRepository/namespace`,
1346+
value: `${refNamespace}`,
1347+
force: true,
1348+
})
1349+
commit('wizard/model$update', {
1350+
path: `/spec/init/archiver/manifestRepository/name`,
1351+
value: `${refDBName}-manifest`,
1352+
force: true,
1353+
})
1354+
commit('wizard/model$update', {
1355+
path: `/spec/init/archiver/manifestRepository/namespace`,
1356+
value: `${refNamespace}`,
1357+
force: true,
1358+
})
1359+
1360+
const resp = getComponentLogStats(snapshotsResp.data)
1361+
1362+
commit('wizard/model$update', {
1363+
path: `/spec/init/archiver/recoveryTimestamp`,
1364+
value: convertToUTC(resp?.end),
1365+
force: true,
1366+
})
1367+
commit('wizard/model$update', {
1368+
path: `/minDate`,
1369+
value: convertToUTC(resp?.start),
1370+
force: true,
1371+
})
1372+
commit('wizard/model$update', {
1373+
path: `/maxDate`,
1374+
value: convertToUTC(resp?.end),
1375+
force: true,
1376+
})
1377+
} catch (e) {
1378+
pointIntimeError =
1379+
e.response?.data?.message || 'Invalid name / namespace for recovery timestamp'
1380+
commit('wizard/model$update', {
1381+
path: `/spec/init/archiver/recoveryTimestamp`,
1382+
value: '',
1383+
force: true,
1384+
})
1385+
commit('wizard/model$update', {
1386+
path: `/minDate`,
1387+
value: '',
1388+
force: true,
1389+
})
1390+
commit('wizard/model$update', {
1391+
path: `/maxDate`,
1392+
value: '',
1393+
force: true,
1394+
})
1395+
commit('wizard/model$delete', '/spec/init/archiver/encryptionSecret')
1396+
commit('wizard/model$delete', '/spec/init/archiver/fullDBRepository')
1397+
commit('wizard/model$delete', '/spec/init/archiver/manifestRepository')
1398+
console.log(e)
1399+
}
1400+
}
1401+
1402+
function convertToUTC(localTime) {
1403+
const date = new Date(localTime)
1404+
if (isNaN(date.getTime())) return
1405+
1406+
const utcString = date.toISOString()
1407+
return utcString
1408+
}
1409+
1410+
function onTimestampChange() {
1411+
const localTime = getValue(model, '/spec/init/archiver/recoveryTimestamp')
1412+
if (!localTime) return
1413+
1414+
const utcString = convertToUTC(localTime)
1415+
1416+
// Only update if the value is valid & not already in UTC format
1417+
if (utcString && localTime !== utcString) {
1418+
commit('wizard/model$update', {
1419+
path: '/spec/init/archiver/recoveryTimestamp',
1420+
value: utcString,
1421+
force: true,
1422+
})
1423+
}
1424+
}
1425+
13111426
return {
13121427
isExternallyManaged,
13131428
showReferSecretSwitch,
@@ -1367,5 +1482,8 @@ export const useFunc = (model) => {
13671482
onModeChange,
13681483
setBackup,
13691484
getDefault,
1485+
setPointInTimeRecovery,
1486+
onTimestampChange,
1487+
showRecovery,
13701488
}
13711489
}

0 commit comments

Comments
 (0)