From 7e84932ab47899751589f77ac041cf5d91a8674a Mon Sep 17 00:00:00 2001 From: Nihal Azmain Date: Tue, 24 Dec 2024 12:14:44 +0600 Subject: [PATCH] Add form to Expose via Gateway for all db that has expose via gateway Signed-off-by: Nihal Azmain --- charts/kubedbcom-kafka-editor/ui/edit-ui.yaml | 16 ++++++++ charts/kubedbcom-kafka-editor/ui/functions.js | 39 +++++++++++++++++++ .../kubedbcom-mariadb-editor/ui/edit-ui.yaml | 16 ++++++++ .../kubedbcom-mariadb-editor/ui/functions.js | 39 +++++++++++++++++++ .../kubedbcom-mongodb-editor/ui/edit-ui.yaml | 16 ++++++++ .../kubedbcom-mongodb-editor/ui/functions.js | 39 +++++++++++++++++++ charts/kubedbcom-redis-editor/ui/edit-ui.yaml | 16 ++++++++ charts/kubedbcom-redis-editor/ui/functions.js | 39 +++++++++++++++++++ .../ui/edit-ui.yaml | 16 ++++++++ .../ui/functions.js | 39 +++++++++++++++++++ 10 files changed, 275 insertions(+) diff --git a/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml b/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml index f3ab4ab3b..3889a4708 100644 --- a/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-kafka-editor/ui/edit-ui.yaml @@ -1141,4 +1141,20 @@ steps: type: single-step-form id: storage-autoscaler title: steps.7.label +- form: + discriminator: + binding: + default: false + type: boolean + elements: + - computed: isBindingAlreadyOn + label: + text: Expose Binding + onChange: addOrRemoveBinding + type: switch + schema: + $ref: discriminator#/properties/binding + type: single-step-form + id: binding + title: steps.8.label type: multi-step-form diff --git a/charts/kubedbcom-kafka-editor/ui/functions.js b/charts/kubedbcom-kafka-editor/ui/functions.js index ebf5e062c..506782f76 100644 --- a/charts/kubedbcom-kafka-editor/ui/functions.js +++ b/charts/kubedbcom-kafka-editor/ui/functions.js @@ -1293,6 +1293,43 @@ function handleUnit({ commit, model, getValue }, path, type = 'bound') { } } +function isBindingAlreadyOn({ model, getValue }) { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComKafkaBinding') + return isExposeBinding +} + +async function addOrRemoveBinding({ commit, model, getValue, discriminator }) { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'KafkaBinding', + metadata: { + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + await commit('wizard/model$update', { + path: '/resources/catalogAppscodeComKafkaBinding', + value: bindingValues, + force: true, + }) + } else { + await commit('wizard/model$delete', '/resources/catalogAppscodeComKafkaBinding') + } +} + return { handleUnit, isConsole, @@ -1376,4 +1413,6 @@ return { getOpsRequestUrl, getCreateNameSpaceUrl, setStorageClass, + isBindingAlreadyOn, + addOrRemoveBinding, } diff --git a/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml b/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml index 98c010e49..17cf89d49 100644 --- a/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mariadb-editor/ui/edit-ui.yaml @@ -1238,4 +1238,20 @@ steps: type: single-step-form id: storage-autoscaler title: steps.10.label +- form: + discriminator: + binding: + default: false + type: boolean + elements: + - computed: isBindingAlreadyOn + label: + text: Expose Binding + onChange: addOrRemoveBinding + type: switch + schema: + $ref: discriminator#/properties/binding + type: single-step-form + id: binding + title: steps.11.label type: multi-step-form diff --git a/charts/kubedbcom-mariadb-editor/ui/functions.js b/charts/kubedbcom-mariadb-editor/ui/functions.js index 199fdf4c3..203e5019e 100644 --- a/charts/kubedbcom-mariadb-editor/ui/functions.js +++ b/charts/kubedbcom-mariadb-editor/ui/functions.js @@ -2301,6 +2301,43 @@ function objectCopy(obj) { return JSON.parse(temp) } +function isBindingAlreadyOn({ model, getValue }) { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMariaDBBinding') + return isExposeBinding +} + +async function addOrRemoveBinding({ commit, model, getValue, discriminator }) { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MariaDBBinding', + metadata: { + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + await commit('wizard/model$update', { + path: '/resources/catalogAppscodeComMariaDBBinding', + value: bindingValues, + force: true, + }) + } else { + await commit('wizard/model$delete', '/resources/catalogAppscodeComMariaDBBinding') + } +} + return { getDbDetails, isConsole, @@ -2442,4 +2479,6 @@ return { setArchiverSwitch, onArchiverChange, onBackupTypeChange, + isBindingAlreadyOn, + addOrRemoveBinding, } diff --git a/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml b/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml index b6843a0f9..cbd30f1cd 100644 --- a/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-mongodb-editor/ui/edit-ui.yaml @@ -2356,4 +2356,20 @@ steps: type: single-step-form id: storage-autoscaler title: steps.11.label +- form: + discriminator: + binding: + default: false + type: boolean + elements: + - computed: isBindingAlreadyOn + label: + text: Expose Binding + onChange: addOrRemoveBinding + type: switch + schema: + $ref: discriminator#/properties/binding + type: single-step-form + id: binding + title: steps.12.label type: multi-step-form diff --git a/charts/kubedbcom-mongodb-editor/ui/functions.js b/charts/kubedbcom-mongodb-editor/ui/functions.js index 1bf32506a..e92295d12 100644 --- a/charts/kubedbcom-mongodb-editor/ui/functions.js +++ b/charts/kubedbcom-mongodb-editor/ui/functions.js @@ -2805,6 +2805,43 @@ function objectCopy(obj) { return JSON.parse(temp) } +function isBindingAlreadyOn({ model, getValue }) { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComMongoDBBinding') + return isExposeBinding +} + +async function addOrRemoveBinding({ commit, model, getValue, discriminator }) { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'MongoDBBinding', + metadata: { + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + await commit('wizard/model$update', { + path: '/resources/catalogAppscodeComMongoDBBinding', + value: bindingValues, + force: true, + }) + } else { + await commit('wizard/model$delete', '/resources/catalogAppscodeComMongoDBBinding') + } +} + return { handleUnit, setMetadata, @@ -2969,4 +3006,6 @@ return { setArchiverSwitch, onArchiverChange, onBackupTypeChange, + isBindingAlreadyOn, + addOrRemoveBinding, } diff --git a/charts/kubedbcom-redis-editor/ui/edit-ui.yaml b/charts/kubedbcom-redis-editor/ui/edit-ui.yaml index 3add71407..64319b681 100644 --- a/charts/kubedbcom-redis-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-redis-editor/ui/edit-ui.yaml @@ -1640,4 +1640,20 @@ steps: type: single-step-form id: storage-autoscaler title: steps.10.label +- form: + discriminator: + binding: + default: false + type: boolean + elements: + - computed: isBindingAlreadyOn + label: + text: Expose Binding + onChange: addOrRemoveBinding + type: switch + schema: + $ref: discriminator#/properties/binding + type: single-step-form + id: binding + title: steps.11.label type: multi-step-form diff --git a/charts/kubedbcom-redis-editor/ui/functions.js b/charts/kubedbcom-redis-editor/ui/functions.js index 205a99a2c..475fc1aef 100644 --- a/charts/kubedbcom-redis-editor/ui/functions.js +++ b/charts/kubedbcom-redis-editor/ui/functions.js @@ -2562,6 +2562,43 @@ function objectCopy(obj) { return JSON.parse(temp) } +function isBindingAlreadyOn({ model, getValue }) { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComRedisBinding') + return isExposeBinding +} + +async function addOrRemoveBinding({ commit, model, getValue, discriminator }) { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'RedisBinding', + metadata: { + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + await commit('wizard/model$update', { + path: '/resources/catalogAppscodeComRedisBinding', + value: bindingValues, + force: true, + }) + } else { + await commit('wizard/model$delete', '/resources/catalogAppscodeComRedisBinding') + } +} + return { handleUnit, isConsole, @@ -2722,4 +2759,6 @@ return { onArchiverChange, onBackupTypeChange, getNamespaceArray, + isBindingAlreadyOn, + addOrRemoveBinding, } diff --git a/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml b/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml index 69432b94b..329393a5a 100644 --- a/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml +++ b/charts/kubedbcom-singlestore-editor/ui/edit-ui.yaml @@ -758,4 +758,20 @@ steps: type: single-step-form id: storage-autoscaler title: steps.10.label +- form: + discriminator: + binding: + default: false + type: boolean + elements: + - computed: isBindingAlreadyOn + label: + text: Expose Binding + onChange: addOrRemoveBinding + type: switch + schema: + $ref: discriminator#/properties/binding + type: single-step-form + id: binding + title: steps.11.label type: multi-step-form diff --git a/charts/kubedbcom-singlestore-editor/ui/functions.js b/charts/kubedbcom-singlestore-editor/ui/functions.js index 95b18bbf1..7682935d3 100644 --- a/charts/kubedbcom-singlestore-editor/ui/functions.js +++ b/charts/kubedbcom-singlestore-editor/ui/functions.js @@ -2890,6 +2890,43 @@ function objectCopy(obj) { return JSON.parse(temp) } +function isBindingAlreadyOn({ model, getValue }) { + const value = getValue(model, '/resources') + const keys = Object.keys(value) + isExposeBinding = !!keys.find((str) => str === 'catalogAppscodeComSinglestoreBinding') + return isExposeBinding +} + +async function addOrRemoveBinding({ commit, model, getValue, discriminator }) { + const value = getValue(discriminator, `/binding`) + const dbName = getValue(model, '/metadata/release/name') + const dbNamespace = getValue(model, '/metadata/release/namespace') + const bindingValues = { + apiVersion: 'catalog.appscode.com/v1alpha1', + kind: 'SinglestoreBinding', + metadata: { + name: dbName, + namespace: dbNamespace, + }, + spec: { + sourceRef: { + name: dbName, + namespace: dbNamespace, + }, + }, + } + + if (value) { + await commit('wizard/model$update', { + path: '/resources/catalogAppscodeComSinglestoreBinding', + value: bindingValues, + force: true, + }) + } else { + await commit('wizard/model$delete', '/resources/catalogAppscodeComSinglestoreBinding') + } +} + return { handleUnit, isConsole, @@ -3059,4 +3096,6 @@ return { setArchiverSwitch, onArchiverChange, onBackupTypeChange, + isBindingAlreadyOn, + addOrRemoveBinding, }