diff --git a/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml b/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml index 77688ad336..7100d7d891 100644 --- a/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml +++ b/charts/kubedbcom-redis-editor-options/ui/create-ui.yaml @@ -174,6 +174,9 @@ step: label: Shards schema: temp/announceShards type: array-item-form + validation: + type: custom + name: validateAnnounceShards watcher: func: onAnnounceShardsChange paths: diff --git a/charts/kubedbcom-redis-editor-options/ui/functions.js b/charts/kubedbcom-redis-editor-options/ui/functions.js index fcd9741431..810e74ba42 100644 --- a/charts/kubedbcom-redis-editor-options/ui/functions.js +++ b/charts/kubedbcom-redis-editor-options/ui/functions.js @@ -1113,6 +1113,7 @@ export const useFunc = (model) => { .map((endpoint) => endpoint.trim()) .filter((endpoint) => endpoint), })) + commit('wizard/model$update', { path: '/spec/cluster/announce/shards', value: transformed, @@ -1120,6 +1121,25 @@ export const useFunc = (model) => { }) } + function validateAnnounceShards() { + const shards = getValue(discriminator, '/announceShards') || [] + const master = getValue(model, '/spec/cluster/master') || 0 + const replicas = getValue(model, '/spec/cluster/replicas') || 0 + if (shards.length !== master) { + return `Shards Length should be equal to master(${master})` + } + for (let i = 0; i < shards.length; i++) { + const shard = shards[i] + const endpoints = shard + .split(',') + .map((endpoint) => endpoint.trim()) + .filter((endpoint) => endpoint) + if (endpoints.length !== replicas) { + return `Each Shard should have ${replicas} comma-separated endpoints, but found ${endpoints.length}.` + } + } + } + function setBackup() { const backup = getValue(model, '/spec/backup/tool') const val = getValue(model, '/spec/admin/backup/enable/default') @@ -1448,6 +1468,7 @@ export const useFunc = (model) => { isVariantAvailable, notEqualToDatabaseMode, onAnnounceShardsChange, + validateAnnounceShards, onAuthChange, onBackupSwitch, onCreateSentinelChange,